Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Attempting webservice connection using HttpURLConnection

  1. #1
    Junior Member
    Join Date
    Feb 2023
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Attempting webservice connection using HttpURLConnection

    Hi. I am attempting to make a webservice connection that we used to have working. But something has changed *somewhere*.

    So I am back to testing a basic connection and even that is now giving me issues....( see code below )

    java.net.ConnectException: Connection refused (Connection refused) <--- Yes I have googled this error and gone through the list of possible causes.


    I CAN use java sockets and connect to google, can ping Google for example... etc.

    BUT this webservice domain btw has three parts.... so when I hit the webservice it looks like this. "https://app.edgtechnology.com/api/list/1/1/" Which I can browse to with Firefox and see the json. But cannot PING the same url from command line.

    The below code fails. Just like the code that used to work connecting to the webservice now instantly fails..... as if the command to go out onto the internet were being blocked.

    I have turned off firewalls, tried https, changed Java security settings but to no avail! I could very well be missing something basic, but have no idea.

    I am on OSX using Java 1.8.0_341-b10

    --- CODE ---

    URL url22 = new URL("http://www.someurl.com");
    HttpURLConnection urlConnect = (HttpURLConnection) url22.openConnection();

    // trying to retrieve data from the source. If offline, this line will fail:
    Object objData = urlConnect.getContent(); // <---- connection refused error

    --- Update ---

    Exception in thread "main" java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(Abstrac tPlainSocketImpl.java:476)
    at java.net.AbstractPlainSocketImpl.connectToAddress( AbstractPlainSocketImpl.java:218)
    at java.net.AbstractPlainSocketImpl.connect(AbstractP lainSocketImpl.java:200)
    at java.net.Socket.connect(Socket.java:606)
    at java.net.Socket.connect(Socket.java:555)
    at sun.net.NetworkClient.doConnect(NetworkClient.java :180)
    at sun.net.http://www.http.HttpClient.openServe...ient.java:499)
    at sun.net.www.http.HttpClient$1.run(HttpClient.java: 551)
    at sun.net.www.http.HttpClient$1.run(HttpClient.java: 549)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.http://www.http.HttpClient.privilege...ient.java:548)
    at sun.net.http://www.http.HttpClient.openServe...ient.java:589)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java :278)
    at sun.net.www.http.HttpClient.New(HttpClient.java:375)
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1247)
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1194)
    at sun.net.http://www.protocol.http.HttpURLConn...ion.java:1061)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:995)
    Last edited by danglyLingham; February 13th, 2023 at 03:33 PM.

  2. #2
    Junior Member
    Join Date
    Mar 2023
    Location
    Vancouver, Canada
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Attempting webservice connection using HttpURLConnection

    It sounds like with the endpoint you are trying to reach refused to allow your side to connect, or something in the path (network firewall) is blocking it.

    Have you tried accessing the same URL using something like curl or wget?

    Have you tried using a network sniffer such as wireshark or tcpdump to see what is happening on the wire?

Similar Threads

  1. Replies: 1
    Last Post: September 2nd, 2014, 08:14 AM
  2. Replies: 1
    Last Post: August 21st, 2014, 01:49 PM
  3. Replies: 0
    Last Post: August 21st, 2014, 06:25 AM
  4. Replies: 0
    Last Post: September 21st, 2012, 11:11 AM
  5. Attempting to get to next level in API
    By meathead in forum The Cafe
    Replies: 8
    Last Post: October 12th, 2011, 11:17 AM

Tags for this Thread