The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: Calling WebService over Http

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 6 - Last Post: Aug 15, 2007 11:06 AM by: whartung
jsl123

Posts: 95
Calling WebService over Http
Posted: Aug 14, 2007 4:31 AM
  Click to reply to this thread Reply

Hi, i have an application that needs to talk to a web service that is implemented as a straight http get request and it is unlikely to change. If it was a "proper" web service, then i could use the java webservice client code to call it, however as it isn't i wondered if anyone could advise on the best cause of action.

Firstly is it ok to make an external http call within a managed function (I was probably going to use a message queue around the calls as well to allow for timeouts, etc)? Are there any issues i should be aware of? Ideally the call would run in its own thread which is why i was thinking of wrapping it in a message queue.

Secondly if the above isn't possible/advised, what would people suggest instead. I've thought about using a JCA connector to wrap the call up with, but again not sure if this is suitable.

Thanks in advance for you suggestions

Ed Mooney
Re: Calling WebService over Http
Posted: Aug 14, 2007 8:32 AM   in response to: jsl123
  Click to reply to this thread Reply

It seems to me your method just needs to use HttpURLConnection to
retrieve some data. I'm not understanding the need to wrap it with JMS
or JCA, even if the method's transacted (if that's what you mean by
managed).

-- Ed

glassfish@javadesktop.org wrote:
> Hi, i have an application that needs to talk to a web service that is implemented as a straight http get request and it is unlikely to change. If it was a "proper" web service, then i could use the java webservice client code to call it, however as it isn't i wondered if anyone could advise on the best cause of action.
>
> Firstly is it ok to make an external http call within a managed function (I was probably going to use a message queue around the calls as well to allow for timeouts, etc)? Are there any issues i should be aware of? Ideally the call would run in its own thread which is why i was thinking of wrapping it in a message queue.
>
> Secondly if the above isn't possible/advised, what would people suggest instead. I've thought about using a JCA connector to wrap the call up with, but again not sure if this is suitable.
>
> Thanks in advance for you suggestions
> [Message sent by forum member 'jsl123' (jsl123)]
>
> http://forums.java.net/jive/thread.jspa?messageID=230788
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


jsl123

Posts: 95
Re: Calling WebService over Http
Posted: Aug 15, 2007 4:03 AM   in response to: Ed Mooney
  Click to reply to this thread Reply

The reason for wrapping it up in a JMS queue is mainly a design issue, so that i can push a load of requests and have them processed as quick as the other server can handle them.

whartung

Posts: 634
Re: Calling WebService over Http
Posted: Aug 14, 2007 2:19 PM   in response to: jsl123
  Click to reply to this thread Reply

Basically, there's nothing in the JEE specs that prevents you from opening a socket to connect to another machine. Rather, there's limitations on opening a socket to accept connections.

So, if you want to call an HTTP server through a socket, you're AOK to do that. You can use the built in Java support, or look at a library, like Commons HttpClient from Apache to help manage this.

jsl123

Posts: 95
Re: Calling WebService over Http
Posted: Aug 15, 2007 4:02 AM   in response to: whartung
  Click to reply to this thread Reply

Cheers, I wasn't sure if there were any guidelines and i couldn't find any information about it. I knew there were restrictions with threads and wondered if anything like that applied to sockets (or other resources). That makes life simple.

mjparme

Posts: 6
Re: Calling WebService over Http
Posted: Aug 15, 2007 6:58 AM   in response to: jsl123
  Click to reply to this thread Reply

Just out of curiosity what do you consider a "proper" web service? A web service is simply a URL endpoint that returns data. Whether that data is delimited text, XML, a message using the SOAP protocol, etc. doesn't matter. Just call it wherever you would call it for any web service.

For a web service that takes name/value pairs as input and returns data in the response body commons HttpClient is probably your best bet:

http://commons.apache.org/httpclient/

If you want to pursue using a JMS queue with your HTTP requests ActiveMQ is probably worth a look:

http://activemq.apache.org/

Particularly this page will probably be useful to you:

http://activemq.apache.org/rest.html

whartung

Posts: 634
Re: Calling WebService over Http
Posted: Aug 15, 2007 11:06 AM   in response to: mjparme
  Click to reply to this thread Reply

> Just out of curiosity what do you consider a "proper"
> web service? A web service is simply a URL endpoint
> that returns data. Whether that data is delimited
> text, XML, a message using the SOAP protocol, etc.
> doesn't matter. Just call it wherever you would call
> it for any web service.

By "proper" web service, he meant "a web service for which there is tooling and plumbing support directly in the server", i.e. a web service that he could use the high level WS APIs to access, with the expectation that whatever chicanery may be involved in dealing with a remote client within a JEE server, the API and bundled software would handle it.

Versus making direct socket calls himself and managing the resources manually for an "unsupported" web service.

As the REST APIs get bundled in to the Java WS stack, obviously this kind of simple GET web resource will be able to be managed by the servers WS stack. But for now you need to "roll your own" (ideally via the higher level utilities like URLConnection or HttpClient) rather than relying on the servers facilities to handle that transaction for you.




 XML java.net RSS