apt vs wsgen vs wsimport .Confusion on what to use when and why not to use the other
Asked Answered
L

1

9

I have been trying to write a web service (JAX-WS) and I have gone through a number of tutorials ranging from 2006 to 2013 ones. Most of them are with respect to some IDE. Those which talk about manual creation/deployment of web service are with ant scripts. Till here everything is fine.

The moment I check the ant scripts, the confusion starts. some old tutorials use APT task to compile the SEI and then wsgen is used to generate the artifacts. the newer ones use only wsgen (although APT is defined as taskdef in ant scripts). Also , as I have been reading about the JAVA 7 documentation, it says you dont need to use wsgen as javac itself does all compilations and the artifacts req. for WS is generated at runtime dynamically.

I tried to use javac command on SEI and deployed it on tomcat but it didnt work.

Can anyone please clarify as in what commands I need to use in JAVA SE 7 edition to deploy a web service.

Also, I want to know what does each command generate and when to use which commands.

According to my knowledge wsimport is not needed for development and deployment , but only need to build the WS-client. Is this correct? If not please provide me pointers to clear my understanding.

Thanks in Advance

Also if I am repeat my self then sorry as I am new to StackOverflow and not very familiar with this. :)

Laureate answered 6/4, 2014 at 13:33 Comment(0)
H
15

To create a Web Service using the Java-WS specification, you need several artifacts. The purpose of "apt", "wsgen" and "wsimport" is to automate this procedure.

There are two ways to create a Web Service: Bottom-Up (First code, then WSDL) and Top-Down (First WSDL then code).

Bottom-Up approach:

  • apt: Uses source code, generates WSDL (and artifacts)
  • wsgen: Uses compiled code, generates WSDL (and artifacts)

Top-Down

  • wsimport: Uses the WSDL, generates java code for the service/client implementation.

The advantage of using apt is that having the source code the script will be able to get the parameters names and use them on the WSDL.

Web Service Deployment

For production you would need a Web Container which can be in charge of security, scalability and resource management, however, for testing purposes you can deploy your web services using the built-in web server on Java SE by doing:

 @WebService 
 public class MyService {
                                          
    public static void main(String args[]) {   
        MyService service = new MyService();   
        String url = "service/";   
        Endpoint ep = new Endpoint(url, service); 
    }
     

    @WebMethod 
    public String getInfo() {   
        return "Service info"; 
    }
}

This piece of code would generate the WSDL and publish the service at your localhost/service.

Hydrothorax answered 6/4, 2014 at 14:53 Comment(2)
Thanks...This gives me a basic idea to write the JAX-WS specification compliant web service. Now w.r.t apt and wsgen, do I need to use any of those explicitly/?? bcz I was able to deploy Myservice class without any of those and it did work fine...Laureate
No, you don't. "This piece of code would generate the WSDL and publish the service at your localhost/service". The Endpoint class will execute wsgen for you. If you find this answer helpful please select "this answer is helpfull" or even better, "accept" the answer.Hydrothorax

© 2022 - 2024 — McMap. All rights reserved.