Java Reference
In-Depth Information
import javax.jws.WebService;
import org.apache.log4j.Logger;
/**
* This annotation will produce a WSDL URL of:
* http://localhost:8080/soaCookbookWS/CatalogService?wsdl
* That's because it is in the web context of "soaCookbookWS",
* which is the WAR name, appended with the value of the
* serviceName property.
*
* Use that value in the properties file to generate client
* artifacts.
*/
@WebService(serviceName="CatalogService", name="Catalog",
targetNamespace="http://ns.soacookbook.com")
public class CatalogWS implements Catalog {
private static final Logger LOGGER =
Logger.getLogger(CatalogWS.class);
@WebMethod
public @WebResult(name="title") String
getTitle(
@WebParam(name="id") String id) {
if ("12345".equals(id)) return "Hamlet";
if ("98765".equals(id)) return "King Lear";
if ("55555".equals(id)) return "Macbeth";
return "--Item not in catalog--";
}
public CatalogWS() { }
}
The code in Example 6-6 is the servlet that will get the @WebServiceRef annotation and re-
ceive the service injection from the container at runtime.
Example6-6.InjectionServlet.java uses @WebServiceRef to refer to a web service
public class InjectionServlet extends HttpServlet {
@WebServiceRef(type=Catalog.class)
private CatalogService service;
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
Search WWH ::




Custom Search