• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to access an External Web Service from a Web Service

 
Ranch Hand
Posts: 167
Netbeans IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets say I have an EJB web service on a server in New York which keeps banking information.

And I have an EJB web service on a server in Los Angeles which keeps inventory information.

Now I am creating invoices and purchase orders.  I need to get my accounts from the New York Web Service and I need to get the Inventory from the LA web service from an EJB web service which is on a server in Oklahoma.

I know how to get it from a front end app.  But how do I do this inside a web service EJB?

Not sure if it matters or not but I am using WebLogic as my app servers.  
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not too familiar with EJ‍Bs, but does "web service EJB" mean that they have a SOAP or REST frontend? If so, you sh‍ould be able to create Ja‍va client code for that, and use it wherever you want to access them. Obviously, that depends on the network being set up to allow HTTP between all involved hosts. I don't think the kind of server plays a role in this.
 
Michelle Nicholes
Ranch Hand
Posts: 167
Netbeans IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I did some research on how to access a web service through a java class.
I found that I could generate java files and classes using:

wsimport -s src -d bin http://localhost:1234/Accounts/AccountsService?wsdl

And I did this.

I then created this code which worked.



But since I have the code for the web service itself and I do have the Client @Remote interface and dto's.  Is there a better way without having to generate the java code and classes using the wsimport command every time I add new methods?

 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at Apache CXF framework. This link provides some hints to start from, even though I am not sure the approach suggested is  straightforward.
 
Michelle Nicholes
Ranch Hand
Posts: 167
Netbeans IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where I am at now on this is that in the main EJB Client, I added a linked folder of the Client of the external Web Service which contained the Interface and the DTOs.  In the project folder of the EJB, I added the package path for the external and I created an Interface class which is the exact same name as the external Web Service and copied into it the Interface but changed the annotation from @Remote to @WebService.   I then created another Java Class to hold the connection to the external web service and then added methods which called the methods I needed from the external web service.  And then in the actual Main EJB, during the methods which I needed the external information, I instantiated the Java Class to open the connection and then I called the method to get the data.  So far, I have run the application and I did the gets and everything worked.  I have not yet tested a set yet.  But at least the gets did work.  I was able to get data from an external web service EJB while in a web service EJB.  It did work.




 
It's just a flesh wound! Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic