Solved

OData4j client which port am i using?

Posted on 2013-01-09
13
493 Views
Last Modified: 2013-01-11
Dear Experts,

I am working on a project where i need to connect to a OData service with Java. Now I get the
java.net.ConnectException: Connection timed out. I believe this is because of the firewall at my work. However, now I need to get the port number so that they can give access to the site and open the port for me. My problem now is I don't know which port i am using, so how can i find out which port i am using?
I hope someone can help me! thanks in advance!

Cheers,

Mark Vrenken
0
Comment
Question by:MarkVrenken
  • 6
  • 5
  • 2
13 Comments
 
LVL 16

Assisted Solution

by:krakatoa
krakatoa earned 60 total points
ID: 38758124
Socket.getLocalPort(). Or .getPort() if you want the remote port.

Which of course can only work if you are connected.
0
 
LVL 1

Author Comment

by:MarkVrenken
ID: 38758254
I'm sorry I have no experience with this, so what should i try to do now?
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 38758310
Ask the people at the server end how you should connect.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38758392
Connection timed out. I believe this is because of the firewall at my work.
What makes you think that? The last url you gave for the resource didn't work for me and i don't have any firewall problems.
0
 
LVL 1

Author Comment

by:MarkVrenken
ID: 38759125
Because the URL worked on my laptop but not on the pc at work...  you are probably you are right but what is the problem then? why is it working on my laptop but not on the pc at work?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38759153
It's not impossible that it could be a firewall issue, but please post your current code, preferably with testable url
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:MarkVrenken
ID: 38759264
package odataconsumerant;

import java.io.*;
import java.net.Socket;
import org.odata4j.consumer.ODataConsumer;
import org.odata4j.consumer.ODataConsumers;
import org.odata4j.consumer.behaviors.OClientBehaviors;
import org.odata4j.core.OEntity;
import org.statkraft.ODataConsumers.AbstractExample;

public class ODataConsumerXL extends AbstractExample {

    public static void main(String[] args) throws NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, IOException, CertificateException, UnrecoverableKeyException {
        ODataConsumerXL example = new ODataConsumerXL();
        example.run(args);
    }

    private void run(String[] args)  {
        
        
       ODataConsumer c = ODataConsumers.create("http://services.odata.org/OData/OData.svc/");

        for (OEntity suppliers : c.getEntities("Supplier").execute()) {
            System.out.println(suppliers.getProperty("Name").getValue());
      

        }

    }
}

Open in new window

CEHJ i have no experience with odata4j so i think I make a lot of mistakes during this process. It would also help if i could find a good tutorial on this. But i am very grateful that you are willing to help me. What i forgot to ask is how do you no the URL is not working? because i can go to them through my browser, so thats why i am assuming they work, but that may be a stupid thought. in any case, thanks for your help!

Also regarding the accessibility i think it is still live and i thought it was accessible because it is meant for learning/practice use.
0
 
LVL 1

Author Comment

by:MarkVrenken
ID: 38759346
Sorry there was a typo in the code so i edited it....
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 440 total points
ID: 38760210
for (OEntity suppliers : c.getEntities("Categories").execute()) {

Open in new window

Using the above instead in your code produces the following for me:

Food
Beverages
Electronics

Open in new window

0
 
LVL 1

Author Comment

by:MarkVrenken
ID: 38762157
Hi CEHJ,

Thanks for your reply. I will now try to make a connection without odata4j to see if i can open the connection... or if it is blocked, i have no idea how but I am now searching the internet for a test.

thanks for your responses
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38762555
Make the same change as i did and let us know what happens with your own code
0
 
LVL 1

Author Comment

by:MarkVrenken
ID: 38766459
I made the same changes, and now found out that it is probably my JAVA connection to the internet/network in general that is the problem. Because my netbeans cannot connect to the internet at all. I think therefore i cannot connect to the internet with my code as well.... I think because this is really off-topic of my original question so i will create a new thread with the new question. Thanks for all the help and suggestions! it is much appreciated!

Kind regards,

Mark Vrenken
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38766542
:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ArrayIndexOutOfBoundException 9 68
Image decoding from Camera 3 72
custom annotations 9 32
configure dependency in POM for new database 3 17
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now