In this case we just create our Java interface and implementation and annotate them with JSR-181 annotations. After this WSDL can be retrieved by going to http://<server_name>:8080/<war_name>/services/<serviceName>?wsdl
Here is a step-by-step manual for doing this:
- First start as normal POJO object that implements functionality you need to expose as WS:
package com.industria.order.validation;
public class AllocatedResourceVerificationImpl implements AllocatedResourceVerification{
public void validate(String resourceId, String resourceName, String resourceValue) throws ValidationException{
log.info("Invoked: "+resourceName);
}
} - Extract all functions needed into interface, this helps separate implementation from definition, and is always a good thing (TM) to program to interfaces, so we have
package com.industria.order.validation;
public interface AllocatedResourceVerification {
public void validate(String resourceId,String resourceName,String resourceValue) throws ValidationException;
}package com.industria.order.validation;
public class AllocatedResourceVerificationImpl implements AllocatedResourceVerification{
public void validate(String resourceId, String resourceName, String resourceValue) throws ValidationException{
log.info("Invoked: "+resourceName);
}
} - Anotate interface - this is needed only if we gonna use XFire automatic handling of JSR181 annotated classes (see Exporting WebService - Using XFire with Spring and JSR181 Annotations)
- Anotate interface with a @WebService anotation, the only nessesary parameter is targetNamespace,
- Anotate each method you want to expose with @WebMethod anotation
- If you want parameter of operations to have a names in WSDL, anotate them with @WebParam
package com.industria.order.validation;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(targetNamespace = "http://www.industria.com/contracts/Addons/Salesforce/OrderManager")
public interface AllocatedResourceVerification {
@WebMethod
public void validate(@WebParam(name = "resourceId")String resourceId,
@WebParam(name = "resourceName")String resourceName,
@WebParam(name = "resourceValue")String resourceValue) throws ValidationException;
}
- Anotate interface with a @WebService anotation, the only nessesary parameter is targetNamespace,
- Anotate implementaion
- You must put @WebService anotation
- giving serviceName - this is name with which this service will be exported by XFire
- and endpointInterface - this is pointer to the interface we implement
package com.industria.order.validation;
import javax.jws.WebService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@WebService(serviceName = "AllocatedResourceVerification",
endpointInterface = "com.industria.order.validation.AllocatedResourceVerification")
public class AllocatedResourceVerificationImpl implements AllocatedResourceVerification{
protected static final Log log = LogFactory.getLog(AllocatedResourceVerificationImpl.class);
public void validate(String resourceId, String resourceName, String resourceValue) throws ValidationException{
log.info("Invoked: "+resourceName);
}
}
- giving serviceName - this is name with which this service will be exported by XFire
- You must put @WebService anotation