Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

best way test webservice inside java process

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java process which is listening to ActiveMQ messages and I want to call some other webservices (around 8-10) inside the if block (location shown in the code below ). What is the best way to call webservices from Java code? DO I need to open HttpCOnnection 8-10 different times and then call? ALl of these webservices are POST operations, so basically the status is COMPLETE I want to insert stuff using these webservices. Thanks

    }
 
Saloon Keeper
Posts: 22011
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure you do.

HTTP is not a continuous-connection protocol. Instead, each request opens a connection to the server as well as a response socket, sends the request data, receives a response, then closing both the request and response sockets.

It's not uncommon, in fact, for a typical web page with images, CSS, javascript and the like to initiate a dozen or more connections for a single page fetch. Browsers are, in fact, designed with that in mind - they typically run many requests in parallel.

Now for performance reasons, a "keep-alive" mechanism can bypass the full shutdown and re-use resources, but that's a transparent performance mechanism. From a programming point of view, each Request requires a separate connection.
 
Marshal
Posts: 3079
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you are going to be notifying the endpoints synchronously.
    Do the endpoints need to be notified in any particular order?
    What if one of the web service endpoints is unavailable, or a POST operation fails?
        Does it matter?
        Do you need to notify the endpoints which had previously been notified to somehow undo any processing which that may have done based on the notification?
        Do you need to inform the application of the notification failures?

If it were me, I would create an additional message queue for Completion Notification messages, and submit n number of messages to the queue, one  corresponding to each endpoint which needs to be notified, and have a queue listener dedicated to Completion Notification delivery then try and independently deliver the notification to the endpoint.  If the message could not be delivered successfully, it could be put back on the queue for later delivery.
 
Jack Tauson
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:It looks like you are going to be notifying the endpoints synchronously.
    Do the endpoints need to be notified in any particular order?
    What if one of the web service endpoints is unavailable, or a POST operation fails?
        Does it matter?
        Do you need to notify the endpoints which had previously been notified to somehow undo any processing which that may have done based on the notification?
        Do you need to inform the application of the notification failures?

If it were me, I would create an additional message queue for Completion Notification messages, and submit n number of messages to the queue, one  corresponding to each endpoint which needs to be notified, and have a queue listener dedicated to Completion Notification delivery then try and independently deliver the notification to the endpoint.  If the message could not be delivered successfully, it could be put back on the queue for later delivery.



Thanks for your message. Here are answers to your questions inline:

1)Do the endpoints need to be notified in any particular order?

I don't have any requirement like this as of now.

2) What if one of the web service endpoints is unavailable, or a POST operation fails?
Good point. What could be a scenario if one web service end point has to fail? Network connection? Maybe I could use ActiveMQ here as well in some manner so that it could keep on trying again and again until it receives ok response. Not sure if this is a good idea.

3) Do you need to notify the endpoints which had previously been notified to somehow undo any processing which that may have done based on the notification?
Right now I haven't given a thought about it. I think all end points are independent based on my understanding.

4) Do you need to inform the application of the notification failures?
Sounds like a good idea. Probably, I could send an email to myself of the failures based on the webservice response?

Could you please elaborate on additional message queue for Completion Notification messages that you mentioned? like when to call it- do I need to call it independently inside each webservice call?

Question for everyone:

Is this a correct process to follow for calling end points?

https://mkyong.com/java/how-to-send-http-request-getpost-in-java/

Thanks very much !

 
Ron McLeod
Marshal
Posts: 3079
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jack Tauson wrote:Could you please elaborate on additional message queue for Completion Notification messages that you mentioned? like when to call it- do I need to call it independently inside each webservice call?



Sorry for the slow response.

What I was suggesting was to have 2 queues:
  - the one that you have already for events such as COMPLETE
  - another one notifications to the various endpoints

In your code where you have Need to call around 8-10 webservices, rather than serially trying to deliver the notification to a number of endpoint, you could just submit messages to the new queue; one for each endpoint which needs to be notified.

Then you could have a another queue listener which having the responsibility to to deliver the notifications to the endpoint described in the queued message.  I haven't had a need to work with Spring, but I would imagine that you could have a number of worker threads for a particular queue, allowing you to deliver notifications to a number of endpoints concurrently.

 
Jack Tauson
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sorry for the slow response.



No problem. Thanks for elaborating

What I was suggesting was to have 2 queues:
  - the one that you have already for events such as COMPLETE
  - another one notifications to the various endpoints

In your code where you have Need to call around 8-10 webservices, rather than serially trying to deliver the notification to a number of endpoint, you could just submit messages to the new queue; one for each endpoint which needs to be notified.

Then you could have a another queue listener which having the responsibility to to deliver the notifications to the endpoint described in the queued message.  I haven't had a need to work with Spring, but I would imagine that you could have a number of worker threads for a particular queue, allowing you to deliver notifications to a number of endpoints concurrently.



This is how I'm calling couple of webservices (method details not included). If possible, could you maybe provide a pseudo code by modifying the code below to include what you mentioned above? I'm not 100% able to imagine/think what you mentioned above. Sorry about that. Here is what I understood with some more questions below.

I think when you mentioned rather than serially trying to deliver the notification to a number of endpoint, you meant that I should not call the webservices just like I'm doing it right now in the code below?

And when you mentioned you could just submit messages to the new queue; one for each endpoint which needs to be notified. I am wondering at a point when i need to call a web service end point, what message I could send to the queue, did you mean parameters needed to call the webservice?

Also, this listner is deployed on tomcat as WAR. Did you mean to say that I could have a separate java process just like this deployed on tomcat to handle webservice end points?





 
You've gotta fight it! Don't give in! Read this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic