Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Consuming WS Client  RSS feed

 
julio boll
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, I've already generated a WS Client by a WSDL File + Axis + TomCat 8 in Deploy level.
But now I don't know what to do to consume those classes. Can you give me a light or some link where it explain better?
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure my answer is going to help of not but I am going to give it a try.

There are front end frameworks which consume the webservices methods and Data Transfer Objects.

There are back end frameworks which create the webservice and then when its created, we deploy that webservice to an app server.  Whether or not the webservice is exposed to the internet is determined on whether the app server is exposed to the Internet or not.

There are two main backend frameworks in Java.  Spring and EJBs.  I use EJBs.  And so that will be what I will discuss in my answer.

I have an EJB which is the web service itself.  That EJB also talks to a second EJB to access Entity Objects which are stored in some kind of database.  This is normally managed using JPA.   Java Persistence API

Also, in my EJB project, I have a remote client  Which contains the DTO's Data Transfer Objects and my Interface which describes what methods are available through my EJB. 

The Front end framework I am using is Flex and the User Interface is FlashBuilder.  In this UI, it has a wizard which if I give it the URL for my WSDL on the appserver, then it will build the DTO Objects and provide access to the Web Services Methods for me.

The front end framework calls the methods that are in the Interface and retrieves the data into the DTO objects. 

So, lets say my Web Service has a method called getAccounts and returns a list of accountDTO.  Since my UI already created the service stuff for me,  All I have to do is call the method from the created service.  ie.  accountsservice.getAccounts(). 
Now since this framework is asynchronous, this call is assigned to a call responder.  So that when the call is returned, the responder then adds the successful respond to an ArrayList of Accounts but basically its like saying List<Accounts> accounts = accountsservice.getAccounts();

So, once my front end gets the request to get accounts, it creates a soap message and sends it to the webservice and asks the webService for the getAccounts Method.  The EJB receives the request and runs that method getAccounts. 
In that method, the EJB contacts the EAO EJB and runs its getAccounts Method which it then uses Jquery and does some basic sql type query but more object oriented. 
Select * from Accounts eo where eo.archived = null     
In this case there is an Entity class called Accounts and we are assigning a variable eo  (Entity Object) and there should be a variable in the Accounts Entity class called archived and we want all records from our associated Database which contains a table with Accounts where archived is null
JPA now instantiates the Accounts Entity Class and runs the query and builds a list of Accounts of Entity type Account.  The result is sent back to the Web Service EJB
The Web Service EJB now takes that List of Entity Accounts and converts them to a list of AccountDTO.  Which is the format your front end understands.  Once it has this list, it sends the result back to the front end via soap which is basically xml
The front end gets the answer and assigns the list of AccountDTOs to what ever variable you defined.  And there you go.  You have access to a list of AccountDTOs and in this case its called accounts
You would use this list just like you would any other arraylist.   Display the data.   Edit the data and send the changes to the webservice with a call like accountsservice.setAccount(AccountDTO).   Whatever you would normally do. 

I hope this helps.
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I forgot to add what the structure looks like for my back end.

I am using eclipse as my IDE

I have a project called

Accounts:
Contains the WebService EJB, Entities, and the EAO EJB and the Conversion utility which converts Entities to DTOs and DTOs to Entities
This also contains the persistence.xml file which jpa uses for jta ad jndi for access to the jdbc database calls.

AccountsClient
Contains the WebService Interface and DTO Classes

AccountsEAR
Contains the Deployment infrastructure.  This is what gets deployed to the app server.

The App Server which I am using WebLogic has Datasources which interface with my Database and allow access through jndi which jta uses through jdbc  The jndi file
And the App Server has Deployed apps which in this case has a web service called AccountsService.  In the Deployed Service, under testing, you would find the WSDL and the URL needed to retrieve it or display it.


On my front end
Accounts  Project
Contains the generated service classes
ValueObjects which contains the DTO classes
And then the front end app which calls these methods and uses these DTO classes.
 
Tim Moores
Saloon Keeper
Posts: 3512
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "consume"? If you have generated the client code already, you just need to add it to your WS client, adapting it as necessary.
 
Michelle Streeter
Ranch Hand
Posts: 120
Eclipse IDE Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to consume my web service from another web service which led me to discover how you actually consume a web service in a plain java class.  Here is what I found.

First, I used wsimport which is provided with my Java JDK.

wsimport -s src -d bin http://localhost:8080/CalcWS/Calculator?wsdl

src is where you want the generated java code
bin is where you want the generated java classes

this generated an Accounts Java class which was an interface
And all the other stuff the wsdl needed too.

Then here is the code I ended up with for web service I have called accounts



I hope this is what you were looking for
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!