mardi 20 août 2013

@ Your web service sir !



With Java 7, we cannot imagine how simple is to make a web services server

//My OneLine Server ! 
package ws;

import javax.xml.ws.Endpoint;

public class ServerLauncher {

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

}
//MyData 
package ws;

public class Mister {
    
    public String name;
}
//My Service
package ws;

import javax.jws.WebService;

@WebService
public class HelloImpl {

    public String hello (Mister m)
    {
        if (m.name.equals(""))
            {return "Hello Nobdy";}
        else 
            {return "Hello " + m.name;}
    }
}

then use your best SoaopUI and test !
then you can enrich the sample with more annotation

you can easily genereate a client using wsimport based on the wsdl there (http://localhost:29057/WS?wsdl)

be careful with the generation, it generate server interfaces ... but annotation has to be cut/copy into the implementation as they are not inherited ...

Aucun commentaire:

Publier un commentaire