Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling URLconnection from EJB session bean  RSS feed

 
Deepti Bhatia
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Am very new to EJB and want to make a http call using URLConnection. Read in one of the threads it is not recommended but can be done. Could someone please post me a sample of this call. Thanks !
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drago,
Welcome to JavaRanch!

To literally answer your question, here is how you make a URL connection from anywhere.

I'm curious why you want to do this from an EJB though. Can you share?
 
Deepti Bhatia
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne,

Got one sample. We have an application that would be talking to another java application via http call. Since we have the application in EJB and servlets, the call would be from EJB.
Is there a better/right way to make this call (EJB/servlets/java class)?

Tried a sample program to connect to localhost and it connects. Need to test writing to server. Have this sample code to write to server. But where do I check if this is gone through. Similarly how do i write something on server and make my application read that data.

//write to server
wr = new OutputStreamWriter(connection.getOutputStream());
wr.write("Hello !");

wr.flush();

Regards,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Drago Last:
Is there a better/right way to make this call (EJB/servlets/java class)?

I think making the call from your servlet layer would be better design. Partially because the spec says not do from the EJB layer. And partially because it sounds like this URL is a service. So the servlet would be calling multiple servlets (URL, one or more EJB calls.)


But where do I check if this is gone through. Similarly how do i write something on server and make my application read that data.

Does the URL return anything? If so, you look at the above link, there is an example of reading back the data returned by yahoo.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!