Solved

Connection Refused exception upon reading/parsing a shortcut file present in network drive

Posted on 2011-03-09
15
597 Views
Last Modified: 2013-11-23
SAXBuilder builder = new SAXBuilder();
     try {
        File f = new File("\\\\bady\\SShare\\mart.xml");
        System.out.println(f.exists());   // Returns False
        System.out.println(f.length());   // Returns 0

        Document document = builder.build(f);  //IOException at this point
        Element root = document.getRootElement();
        Element paragraph = root.getChild("mart_element");
        String content = paragraph.getText();
        System.out.println("content = " + content);
        } catch (JDOMException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
Here mart.xml is a shortcut present in C:\Param\Bin on a windows box. I get the following IOException:

Exception in thread "main" java.net.ConnectException: Connection refused: 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.Socket.connect(Socket.java:524)
        at java.net.Socket.connect(Socket.java:474)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
        at sun.net.NetworkClient.openServer(NetworkClient.java:118)
        at sun.net.ftp.FtpClient.openServer(FtpClient.java:488)
        at sun.net.ftp.FtpClient.openServer(FtpClient.java:475)
        at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:270)
        at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:352)
        at JDOMElementTextContent.parseXml(JDOMElementTextContent.java:36)
        at JDOMElementTextContent.main(JDOMElementTextContent.java:47)
I tried to open Stream from URL using file: protocol but URLConnection.getInputStream throws the same connection refused exception.

Any recommendations would be appreciated?
0
Comment
Question by:gpmattoo8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
  • +1
15 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 35085739
try C:\Param\Bin\mart.xml
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35085764
What does the following give at the command line?
dir \\bady\SShare\mart.xml

Open in new window

0
 

Author Comment

by:gpmattoo8
ID: 35086248
Volume in drive \\bady\SShare\ has no label.
 Volume Serial Number is 60DF-2818

 Directory of \\bady\SShare

File Not Found
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 86

Expert Comment

by:CEHJ
ID: 35086368
The file doesn't exist
0
 

Author Comment

by:gpmattoo8
ID: 35086473
Well, it does.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35086496
Try mapping a network drive to, say, X:
0
 

Author Comment

by:gpmattoo8
ID: 35086575
Thanks for the suggestion!
However i would be running this program from a unix machine eventually.
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 35086618
you might want to pass the file location runtime through commandline arg or some config... so based on the platform you can give the location appropriately.
0
 

Author Comment

by:gpmattoo8
ID: 35086685
Sure i can! But thats not the solution to the underlying problem.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35086692
You might also try a URL as the parameter to the SAXBuilder
0
 

Author Comment

by:gpmattoo8
ID: 35086742
I tried the URL but got the same exception.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35086818
What do you get from the following at the command line?
explorer "\\bady\SShare"

Open in new window

0
 
LVL 26

Expert Comment

by:ksivananth
ID: 35086851
it sounds like \\bady\SShare is an unix share... you can't use this in windows unless it is mapped to win throw something like citrix...
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 35086854
or you download the file to local win and then specify that in the parser
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 35089117
you can convert the file to a url, but if its not finding the file then its not going to find the url either

> However i would be running this program from a unix machine eventually.

You won't get this problem then. This problem is specific to Windows.
I'd suggest accessing the file on one of the local drives (as ksivananth suggested above) for testing, far less troublesome.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 95
Which non-HTML GUI front end to use with Java? 3 67
maximize the sum of fractions 33 76
Java pass by reference 3 75
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question