JAX-WS Service development with WSAS

I’ve started a series of articles on JAX-WS development with WSAS. The first one here, talks about the basics and fundamentals of JAX-WS development. I’ve written some areas of this topic in my previous posts in this blog. But this article brings all together and provides a very easy to follow approach to develop JAX-WS services with WSAS. There will be few more articles coming out on JAX-WS client side development, MTOM support, WS-Security etc. So stay tuned. I’ll post everything on this blog once those articles will be published.

Code First or Contract First with WSAS?

“Code First or Contract First?”. This has been a hot topic in the Web services world for many years among the Web service developers. In one of my latest articles on WSO2 Oxygen Tank, I’ve discussed this topic in the context of WSO2 WSAS. In this article, you’ll find out how to select the most appropreate approach to be followed when developing your Web Service with WSAS.

How to use MTOM with Axis2 JAX-WS services

If you are new to JAX-WS service development with Axis2, please read this first. In this post, you will find out how to use MTOM functionality in Axis2 JAX-WS services. Here I’m using Axis2 1.5.1.

First of all, you have to use the BindingType annotation to set the SOAP11 MTOM binding as follows.

@BindingType(SOAPBinding.SOAP11HTTP_MTOM_BINDING)

After that, you can use javax.activation.DataHandler to represent your binary data in your parameters or return types. A simple MTOM enabled JAX-WS service class can be written as follows.

@WebService(serviceName = “MTOMSampleService”,
targetNamespace = “http://mtom.jaxws.wso2.org”
)
@BindingType(SOAPBinding.SOAP11HTTP_MTOM_BINDING)

public class MTOMService {

@WebMethod(action = “urn:uploadFile”)
public String uploadFile(DataHandler data) {
try {
InputStream is = data.getInputStream();
….
String msg = “File ” + data.getName() + ” of type ” + data.getContentType() +
” successfully received”;
return msg;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

@WebMethod(action = “urn:getTestData”)
public DataHandler getBinaryTestData(String stmtId) {
byte[] testData = new byte[10240];

for (int i = 0; i < testData.length; i++) {
testData[i] = 0x7f;
}

ByteArrayDataSource bds = new ByteArrayDataSource(
testData, “application/octet-stream”);
return new DataHandler(bds);

}

}

DataHandler objects can be used inside wrapped classes as well.