SocketException caught in Selenium HtmlUnitDriver program - java

I have written a small script that takes the default IP address for Epson printers we receive at my company and changes them automatically according to the requirement. This is done using Selenium HtmlUnitDriver.
The script gets the page, inserts the new IP, and than submits it. Because the IP changes once we submit a second time, the page is no longer 192.168.192.168, and the script does not want to complete.
Below is the script:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Main {
public static void main(String[] args) {
// Creating a new instance of the HTML unit driver.
WebDriver driver = new HtmlUnitDriver();
driver.get("http://192.168.192.168/ctcpip.htm");
// Find and change the IP Address field.
WebElement element = driver.findElement(By.name("IpAddress"));
element.clear();
element.sendKeys("192.168.192.169");
element.submit();
// Reset the printer. This changes it's IP as well, causing the initial driver page to no longer exist.
WebElement reset = driver.findElement(By.name("Submit"));
reset.submit();
// The script never gets this far.
driver.quit();
}
}
The script times out before it can complete. When the reset element is clicked, the initial URL of http://192.168.192.168/ctcpip.htm is effectively nonexistent, since we have changed it to 192.169.192.169. This is expected behavior, and the entire point of the program.
The console reads:
Nov 03, 2016 10:36:52 AM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {}->http://192.168.192.168:80: Operation timed out
Nov 03, 2016 10:36:52 AM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://192.168.192.168:80
Exception in thread "main" java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connect to 192.168.192.168:80 [/192.168.192.168] failed: Operation timed out
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:739)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.processPostponedActions(JavaScriptEngine.java:820)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1325)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1268)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1216)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.submit(HtmlUnitWebElement.java:175)
at Main.main(Main.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 192.168.192.168:80 [/192.168.192.168] failed: Operation timed out
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:178)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1313)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1230)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:338)
at com.gargoylesoftware.htmlunit.WaitingRefreshHandler.handleRefresh(WaitingRefreshHandler.java:92)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1446)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:306)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:475)
at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2074)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:733)
... 11 more
Caused by: java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
... 29 more
Process finished with exit code 1
How do I tell my driver instance that it's totally cool the page changed so the process can exit properly?
The script needs to reach the driver.quit(); line.

Have you tried to call
driver.quit();
before
reset.submit();
? You no longer use the driver to retrieve any element, so you can quit before submitting the page.
I hope it helps.

If something doesn't work with findelement in Selenium, everyone uses js :).
How about this ?
driver.executeScript("window.document.getElementsByName("Submit")[0].click()");
Index could be wrong and need to be adjusted

Please try With the following Code :
It quits the driver in case of the provided Host or Host IPaddress is not available within the network.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Main {
public static void main(String[] args) {
// Creating a new instance of the HTML unit driver.
WebDriver driver = new HtmlUnitDriver();
try{
driver.get("http://192.168.192.168/ctcpip.htm");
WebElement element = driver.findElement(By.name("IpAddress"));
element.clear();
element.sendKeys("192.168.192.169");
element.submit();
// Reset the printer. This changes it's IP as well, causing the initial driver page to no longer exist.
WebElement reset = driver.findElement(By.name("Submit"));
reset.submit();
}
catch(HttpHostConnectException e){
System.out.println("Host Not Found : "+ e.getMessage())
}
finally{
driver.quit();
}
}
}

Related

Catching Java SQLExceptions

I do not have a lot of experience in Java and would appreciate if you bring a light on the question.
I have the following piece of code (method) to establish the JDBC connection with a PostgreSQL database :
public void establishDBConnection() throws SQLException {
try (Connection connection = DriverManager.getConnection(
"jdbc:postgresql://" + dbServer + ":" + dbPort + "/" +
dbDatabase, dbUser, dbPassword))
catch (SQLException e) {
logger.error("Connection to Postgres Database Failed: " +
e.printStackTrace();
}
}
I expect that the SQLException would be caught by the catch block as soon as the method can't establish connection with the database (server is down). The catch block puts the exception on the console but I see that the same exception is displayed earlier right after the getConnection method execution. Thus, I have 2 quite the same exceptions on the console. See below.
The question is what is the reason for this and how to force the application to display only the exception generated by the catch block.
Logs:
Jul 07, 2017 9:11:53 PM org.postgresql.Driver connect
SEVERE: Connection error:
**org.postgresql.util.PSQLException: Connection to localhost:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.**
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:265)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:431)
at org.postgresql.Driver.connect(Driver.java:247)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at excel2db.service.impl.DBConnectionPostgresImpl.establishDBConnection(DBConnectionPostgresImpl.java:38)
at excel2db.excel2db.main(excel2db.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.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 org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)
... 13 more
21:11:53.465 [main] ERROR e.s.impl.DBConnectionPostgresImpl - **Connection to Postgres Database Failed: Connection to localhost:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.**
There is only one exception being printed in your example: the SQLException being caught. What you think is a second exception is only (as the text shows) the cause of the SQLException: Postgres throws a SQLException, which is itself being thrown because there was a network ConnectException when Portgres tried to connect.
This chain of exceptions is very handy when you need to diagnose a failure. It allows going back to the original, low-level source of a problem. Just like, for example, it can be useful to know that you didn't got your mail (NoMailException) because the post office is on strike (OnStrikeException), because the government decided to lower the wages (WagesTooLowException). If you just had the original NoMailException, you wouldn't be able to know the reason why you got no mail, know that it's probably temporary, etc.
In this particular case, you can deduce that it was impossible to connect to the server, and not for example, that the password was incorrect.
Chaining exceptions is simply achieved by calling one of the exception constructors that take another exception as argument (most exceptions do). See https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html#Exception-java.lang.String-java.lang.Throwable-.
You need to load the driver's class into memory. Try This code :
try {
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection(jdbc:postgresql://server_address:5432/database_name?user=usernam&password=password);
} catch (Exception exception) {
exception.printStackTrace();
}

Java Socket ConnectException [duplicate]

This question already has answers here:
What is a connection timeout during a http request
(2 answers)
Closed 27 days ago.
I get an exception when I run this code. Why?
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class MainClass {
public static void main(String[] args) throws Exception {
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
URL url = new URL("https://www.verisign.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
}
}
Exception:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getInputStream(HttpsURLConnectionOldImpl.java:204)
at java.net.URL.openStream(URL.java:1010)
at https.ssl.MainClass.main(MainClass.java:13)
We can't diagnose your networks for you. You need to do it yourself, or get your local admins to look at.
Things you should check before you bug your admins:
can you ping the host?
can you connect to http://www.verisign.com using a web browser?
can you connect to https://www.verisign.com using a web browser?
can you connect to http://www.verisign.com using your program?
can you connect to anything using your program?
The chances are that your problem is firewall related. My first guess would be that you don't have the correct environment variables or Java system properties set to tell the JVM to use a local proxy server for outgoing HTTP / HTTPS requests.
If it is not a problem with your settings, you will need to get help from someone local who can help you diagnose the problem.

TestNG - java.net.SocketException [duplicate]

This question already has answers here:
Official reasons for "Software caused connection abort: socket write error"
(14 answers)
Closed 7 years ago.
My settings :
TestNG 6.9.10 - Java 1.8 - Eclipse Mars.1 Release (4.5.1)
Windows 10
Every time I run a TestNG test suite I have this error :
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
at java.io.ObjectOutputStream.<init>(Unknown Source)
at org.testng.remote.strprotocol.SerializedMessageSender.sendMessage(SerializedMessageSender.java:24)
at org.testng.remote.strprotocol.MessageHub.sendMessage(MessageHub.java:43)
at org.testng.remote.RemoteTestNG$RemoteSuiteListener.onStart(RemoteTestNG.java:257)
at org.testng.SuiteRunner.invokeListeners(SuiteRunner.java:208)
at org.testng.SuiteRunner.run(SuiteRunner.java:266)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Even if my test class is empty :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class sample {
public WebDriver driver;
#Test
public void f() {
}
#BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
driver.get("http://localhost:8081/login.html?profile=desktop");
}
#AfterTest
public void afterTest() {
driver.close();
}
}
The test is running, so it doesn't interfere with the test case, but I really would like to understand and remove this Exception.
Thank you for any idea.
I'm thinking somewhere in WebDriver, java.net is used. Your localhost webserver is closing the socket or it was closed prematurely. Instead of using Before and After test, try to write it all in one Test method and debug. Unfortunately, there's no mention of your class in the stack trace to pinpoint which call is causing the problem.
Step through the following and see where the exception is thrown. If it's on the driver.get call, then your http server is likely rejecting the connections. If it's thrown at the close(), the connection has already been dropped (probably rejected by the server).
#Test
public void test() {
driver = new FirefoxDriver();
driver.get("http://localhost:8081/login.html?profile=desktop");
driver.close();
}

Java try-catch not catching exception

I have the following method:
private void checkIfLoggedIn() {
try{
try {
new WebDriverWait(driver, 10)
.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("a[href*='score']")));
}
catch (WebDriverException e) {
}
loggedInState = 2;
}
catch (TimeoutException e) {
loggedInState = -1;
}
}
Simply put, this method's job is to wait until the webpage finishes loading the logged-in pa
ge, and let the rest of the code know by changing a variable. This code works perfectly the vast majority of the time, however if the driver is closed (by another thread) before it finishes, it crashes. I'm perfectly fine with the code stopping - If the webpage has closed it has most likely finished it's task (or crashed for a different reason). The problem is that the error log (posted below) won't go away. I'v even tried something as broad as catch (Exception e)in order to catch any possible exception, but the crashlog won't go away. Any Advice would be appreciated!
EDIT: Thanks to #jdigital, I discovered that the code was in fact catching the exceptions, however that was masked by Selenium outputting it's own exceptions. Any advice on how to have selenium stop outputting errors would be appreciated!
Jan 27, 2014 6:48:29 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.selector: a[href*='score'])
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: '[Edited out for Privacy]', ip: '[Edited out for Privacy]', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:396)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:432)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:730)
at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:728)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:130)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at Web.WebCrawler.checkIfLoggedIn(WebCrawler.java:89)
at Web.WebCrawler.access$0(WebCrawler.java:86)
at Web.WebCrawler$1.run(WebCrawler.java:80)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:319)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:298)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:366)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 13 more
You should be able to set Selenium's Logging Preferences to customize the exception output.
EDIT:
Perhaps the instructions at the above referenced link aren't too helpful.
It looks like Selenium uses the standard Java logger interface. Get hold of the RemoteWebDriver object and then turn off its logging via setLogLevel(java.util.logging.Level.OFF).
For another alternative, the FirefoxDriver allows stdout/stderr to be redirected to a file. This has the advantage of allowing you to inspect the output should you need to do so; otherwise, you can just overwrite it or delete it.

Connection timed out. Why? [duplicate]

This question already has answers here:
What is a connection timeout during a http request
(2 answers)
Closed last month.
I get an exception when I run this code. Why?
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class MainClass {
public static void main(String[] args) throws Exception {
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
URL url = new URL("https://www.verisign.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
}
}
Exception:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getInputStream(HttpsURLConnectionOldImpl.java:204)
at java.net.URL.openStream(URL.java:1010)
at https.ssl.MainClass.main(MainClass.java:13)
We can't diagnose your networks for you. You need to do it yourself, or get your local admins to look at.
Things you should check before you bug your admins:
can you ping the host?
can you connect to http://www.verisign.com using a web browser?
can you connect to https://www.verisign.com using a web browser?
can you connect to http://www.verisign.com using your program?
can you connect to anything using your program?
The chances are that your problem is firewall related. My first guess would be that you don't have the correct environment variables or Java system properties set to tell the JVM to use a local proxy server for outgoing HTTP / HTTPS requests.
If it is not a problem with your settings, you will need to get help from someone local who can help you diagnose the problem.

Categories

Resources