开发者

Quickly implement, deploy a Webservice in Java

I have a large system written in a mixture of C++, Java, Python. I have to interface a very small subset of this system with a web portal using webservice technology. Webservice is not critical and it has to expose 3 or 4 methods.

What is today the quickest way to implement this in Java? I thoughted AXIS+Tomcat. Maybe is the开发者_StackOverflowre any other newest library?


What is today the quickest way to implement this in Java? I thoughted AXIS+Tomcat. Maybe is there any other newest library?

Yes, there is a much better way. Forget Axis and go for a JAX-WS stack such as JAX-WS RI (which is included in Java 6) or Apache CXF. Here is the usual HelloWorld service with a test method using the built-in HTTP server of the JDK:

package hello;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class Hello {
    @WebMethod
    public String sayHello(String name) {
        return "Hello, " + name + ".";
    }

    public static void main(String[] args) {
        Endpoint.publish("http://localhost:8080/WS/Hello", new Hello());
    }
}

Just run the main method and you're ready to play with the web service.

Of course, you'll want to deploy your web service on a real container for production use. You could go with GlassFish and just deploy your service (GlassFish bundles a JAX-WS runtime). Or you could pick Jetty or Tomcat and install the chosen runtime on it (JAX-WS RI or Apache CXF). Refer to their respective instructions.

Resources

  • Creating a Simple Web Service and Client with JAX-WS
  • JAX-WS Five Minute Tutorial

Related question

  • Getting started with JAX-WS...


there is also project "Jersey" the JSR-311 (JAX-RS) reference implementation. A Framework for Web Services implementing the REST principles, which in my opinion modern Web Services should adhere to. It got lots of tutorials on the web to be found.


Apache Axis2, Apache CXF or Glassfish Metro 2.0 are all pretty up to date and will provide what you need. Spring-WS is probably easier to use than the previous 3, but only if you're already building in the Spring framework. For comparison see:

  • https://stackoverflow.com/questions/519576/would-you-use-metro-instead-of-axis2
  • https://stackoverflow.com/questions/1461921/axis2-versus-sun-metro
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜