|
|
||
Jitendra Kotamraju's BlogMarch 2008 ArchivesJAX-WS RI & DIMEPosted by jitu on March 05, 2008 at 07:06 PM | Permalink | Comments (0)Alternative to JAX-WS RI's wsgenPosted by jitu on March 03, 2008 at 03:13 PM | Permalink | Comments (9)
package pkg;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;
@WebService
public class AddService {
@WebMethod(exclude=true)
public static void main(String ... args) throws Exception {
Endpoint.publish("http://localhost:8181/add", new AddService());
...
}
public int add(int num1, int num2) {
return num1+num2;
}
}
$ javac pkg/AddService.java
$ wsgen.sh -d gen -keep -cp . pkg.AddService
$ ls gen/pkg/jaxws
Add.class AddResponse.class
Here Add.class and AddResponse.class are request and response wrapper bean classes respectively.
So far with JAX-WS RI, you need to run wsgen for doc/lit wrapper case or when service throws any checked exceptions. wsgen generates request/response wrapper bean classes and exception bean classes. JAX-WS spec clearly defined rules to create these portable classes, so that the same application works on different JAX-WS implementations. But all the required information to generate these classes can be got from the SEI, so an implementation may generate these classes on the fly. From JAX-WS RI 2.1.4 onwards, you don't have to run wsgen, the runtime takes care of it by generating these classes dynamically. That's right, you don't have to run "wsgen" ! See the sample logging output, when there are no wrapper classes in the classpath:
$ javac pkg/AddService.java
$java pkg.AddService
INFO: Dynamically creating request wrapper Class pkg.jaxws.Add
Mar 3, 2008 1:58:30 PM com.sun.xml.ws.model.WrapperBeanGenerator createBeanImage
INFO:
@XmlRootElement(name=add, namespace=http://pkg/)
@XmlType(name=add, namespace=http://pkg/, propOrder={arg0, arg1})
public class pkg.jaxws.Add {
@XmlRootElement(name=arg0, namespace=)
public I arg0
@XmlRootElement(name=arg1, namespace=)
public I arg1
}
INFO: Dynamically creating response wrapper bean Class pkg.jaxws.AddResponse
Mar 3, 2008 1:58:30 PM com.sun.xml.ws.model.WrapperBeanGenerator createBeanImage
INFO:
@XmlRootElement(name=addResponse, namespace=http://pkg/)
@XmlType(name=addResponse, namespace=http://pkg/)
public class pkg.jaxws.AddResponse {
@XmlRootElement(name=return, namespace=)
public I _return
}
I would say starting from java, building services have never been so easy :-) Let me know your feedback, you need to try the 2.1.x nightlies for this feature.
| ||
|
|