• Post Reply Bookmark Topic Watch Topic
  • New Topic

upload edi thorugh http protocal

 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I have a use case where we need to upload a edi files or any kind to a vendor location through http protocol.
through basic java code...(no serve lets stuff).


the program causing java.net.connection time out error. at

conn.getOutputstream line.


can some one help or give reference to sample programs

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15713
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us your code? Because otherwise it is impossible to tell if you did it correctly and why you get an error.

Are you using the correct address to connect to? If you get a timeout error, that maybe means that the server is not accepting the connection.
 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is snippet of the code

//urlString: is the path provided by our thrid party vendor to upload the files
Class handlerClass = Class.forName("sun.net.www.protocol.https.Handler");
URLStreamHandler urlStreamHandler = (URLStreamHandler) handlerClass.newInstance();
url = new URL(null, urlString, urlStreamHandler);
conn = (HttpURLConnection) url.openConnection();

conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(true);
for (String key : propertyMap.keySet()) {
conn.setRequestProperty(key, propertyMap.get(key));
}
// property map contains content type username and password
conn.setRequestProperty("Content-Length", "" + length);
conn.connect();
// this step getting connection time out
 
Omkar Shetkar
Ranch Hand
Posts: 86
1
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection time out can occur due to many reasons either from client, server or network.
For me, this issue seems to be broad. To narrow it down, we can perform following checks:
- First need to check whether network and server are not having any issues. Try to ping to your server from your client PC. If able to ping, then network and server are correct. Now, need to check your Java code for correctness. Such as, proxy, security certificate etc.
- If not able to connect to your server from your client PC, then issue could be
- in proxy settings
- check your security certificate configurations
- check firewall
- are you able to resolve host using given DNS
- etc.

In conclusion, we need to narrow down the issue to either client or server.
 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FROM CLIENT BROSWER I AM ABLE TO CONNECT TO THE URLSTRING.

THROUGH JAVA CODE WHEN I AM TRYING THE SAME GETTING CONNECTION TIME OUT.
EVEN IN THIS case will there be an issue with firewall ... ? i mean able connect in browser by typing url and not able to connect through the code given in previous discussion
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeez, KeepItDown. There's no need for all those upper case letters.
 
Omkar Shetkar
Ranch Hand
Posts: 86
1
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not obvious to pin point any particular reason for connection time out. But I will share my frequent experience.
I came across this kind of issue while running Java applications in corporate network.
Usually, in corporate networks proxy is needed to be set to access internet. For this you can check your browser network settings.
If yes, then proxy needs to be set to your application as well.
Refer http://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html on how to set proxy in Java.
 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you omkar,


Yes it looks like corporate network proxy and firewall related issue.
I tried the same code in my personal laptop . And working fine.

I'll try setting proxies through code and check in my office env.
 
Junilu Lacar
Sheriff
Posts: 9983
103
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a lot of experience in programming at that level, that's fine. However, if you'd rather concentrate on the business need and leave the low-level networking concerns to those who have more experience with it, using something like HttpClient would be a better way to go.
 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,


Noted, I didn't observe the caplock is ON while typing so my decision thread is in mixed case.. I didn't mean highlighting.

Thank you. Next time I make it in normal case.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!