• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access an External Web Service from a Web Service

 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • 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. 
 
Tim Moores
Saloon Keeper
Posts: 3255
54
  • Mark post as helpful
  • send pies
  • 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 Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • 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?

 
Claude Moore
Ranch Hand
Posts: 832
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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 Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • 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.




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!