开发者

What technology I should use to develop small Java webservice?

Basically I need webservice where client can request with id one boolean value from our webservice. What technology would be most suitable for this small API? Of course it is possible that there will be more functions to interface, but now we need only one function. It also needs to have authentication, so that only auhtorized clients can access service. And every client have different auth credientials.

What would be good technology for this pu开发者_开发技巧rpose?


I am using resteasy to build my webservices and it is pretty easy to use ... just need to use annotations on my methods to deliver the webservices.

Here is a comparison of different JAX-RS frameworks. Take a look at it


First of all: authentication and authorization. Don't do it yourself, pick an app server or servlet container and configure it to do the job.

For the web service....

The simplest thing to do it just implement a servlet that responds to a POST (not a GET if request modifies internal state) and returns the result in the body. This way you don't need any frames works, no learning to do (if you already know servlets). The downside is it won't scale as you add more features, and your not using enough buzz words.

If you want a SOAP based webservice, then look at JAX-WS. Now that it's backed into java 6 it's pretty easy.

At the simplest level JAX-WS lets you put a few annotations on your class, like @WebService, and it auto generates a wsdl and exposes an instance of your class via the web service.

There is plenty of documenation out around how to do it:

  • http://java.sun.com/webservices/docs/2.0/tutorial/doc/
  • http://www.java-tips.org/java-ee-tips/java-api-for-xml-web-services/developing-web-services-using-j.html
  • http://cwiki.apache.org/GMOxDOC20/simple-web-service-with-jax-ws.html


JAX-WS + any servlet container (Tomcat is usual choice)

@WebService(targetNamespace = "http://affinity.foo.com", name="RewardsStatus")
@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
public interface RewardsStatusIF {
    @WebMethod(operationName="GetLastNotificationDate", action="urn:GetLastNotificationDate")
    @WebResult(name="return")
    public Date getLastNotificationDate() throws AffinityException;
...

Actually, you don't even need a servlet container. JAX-WS has a way to run the service under a standalone Java application. It has some limitations (I have failed to make a stateful service work), but it's very simple to create.


Given that you tagged your question as "Java", I suggest Jetty. It is a very good small servlet engine. It has support for sessions, so adding authentication should not be a problem.


If you are using Java 6, there is already a HTTP Server builtin, it supports Http authentication. That's all you need. Check out,

com.sun.net.httpserver


You could use some restful framework like jersey.


An alternative to SOAP-based web services with JAX-WS would be JAX-RS (for RESTful web services).


We have a lot of scenarios on our project where we want small amounts of data available via simple HTTP URLs while the app is running and in my experience, Restlet (http://www.restlet.org/) seems to be one of the easiest things available for setting up simple "web-service"-like interfaces (RESTful interfaces) within Java apps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜