Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Kindly guide me through this web service implementation  RSS feed

 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I am new to web services. I need some help on how to proceed with a simple web service search that receives an Object and returns a List.

I have already implemented the search method in Java. Now i need to create a web service for that search method.

I would like to know the steps involved in this implentation. Most examples i saw on the internet involve "HelloWorld" but i would i like to receive and return complex java objects.

I have the following setup :

Eclipse (WTP) .
Struts
Spring
Hibernate
Tomcat

I have an interface : IUserService. I want to expose - getAllAddresses as a web service.


public interface IUserService {

public List getAllAddresses(User usr);
}

Here is my User class and Address class :

public class User {
private String username;
public String getUsername(){
return username;
}
public void setUsername(String usernm){
username = usernm;
}
}

public class Address {
private String id = null;
private String street = null;

public Address (String id, String street)
{
this.id = id;
this.street = street;
}

public String getId ()
{
return this.id;
}
public String getStreet ()
{
return this.street;
}
}



 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you need to decide on the WS API to use. The common choices are SOAP and REST, implemented in Java through the JAX-WS and JAX-RS APIs, respectively. Then you need an implementation of the API - for SOAP check out Metro and for REST it's Jersey. Both are web apps that can be run in Tomcat, and can be downloaded from dev.java.net.

As to using Object and List in a web service, you'll need to reconsider that. WS use XML, so anything you want to send over the wire needs to be expressable in XML. As long as the objects follow JavaBeans semantics, that's relatively straightforward, but arbitrary Java objects will not work. And instead of a List you'll need to use arrays.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!