Reputation: 24053
What is the Java equivalent to Script service (like web service but with JSON instead of XML) in the .net world?
I am looking for a way of creating and invoiking web services using java. I prefer to find a way that will allow me define a method that will act as web service. I don't like the solutions of "dedicated jsp or servlet" for the specific request.
Is there any wat of doing so?
Upvotes: 3
Views: 545
Reputation: 61
I would prefer RESTful services which fits for your need of "I prefer to find a way that will allow me define a method that will act as web service." Just with REST annotations You can set a method as a Service.
Code Snippet simple REST
@Path("/rest") public Class MyFirstService {
//Method without Path parameters
@GET
@Path("/name")
@Produces("application/json")
public String getMyName()
{
return "My Name:";
}
//Method with Path parameters
@GET
@Path("/name/{id}")
@Produces("application/json")
public String getMyName(@Pathparam("id")String Id)
{
if(Id.equals("1")
return "My Name:";
else
return "None";
}
}
RESTful Services give four major Services as - GET PUT POST DELETE
Upvotes: 1
Reputation: 4832
You can use libraries like Jersey or RESTeasy for the implementation of web services. For the consumers, you can use the built in classes of the same libraries or, if you prefer, can use Apache HttpClient
I personally prefer using Jersey + HttpClient combination :)
Upvotes: 2
Reputation: 80593
I would recommend JEE6, especially if your focus is going to be on REST based services. Glassfish 3 and JBoss 7 are neck and neck now with their implementation, either would be a good choice (though JBoss is my personal preference). With the JAX-RS and JAS-WS specifications you simply annotate your classes and they become web service capable:
Make your bean a SOAP based web service:
@WebService
public class AccountImpl {
// You can explicitly mark the methods you want to make available in your WSDL
@WebMethod
public BigDecimal getBalance() {}
}
Make your bean a REST based web service:
@Path("/rs/account")
public class AccountImpl {
@GET
@Path("/balance")
@Produces("application/json")
public BigDecimal getBalance() {}
}
The code snippet is just an example. You can find more resources online for learning JAX-RS and JAX-WS. Here are a few links:
Note: I included information about JAX-WS for reference only. You indicated you wanted to build JSON services, which implies REST
Upvotes: 0
Reputation: 115328
There are a lot of frameworks that help you to do this. I personally prefer Spring. But you can just search for "Java based RESTful web services frameworks". Here is a list of such framework from Wikipedia: http://en.wikipedia.org/wiki/List_of_web_service_frameworks
Enjoy.
Upvotes: 2