// full web.xml, just examine all servlet entries for web services
ServletType[] servletTypes = webApp.getServletArray();
for (ServletType servletType : servletTypes) {
String servletName = servletType.getServletName().getStringValue().trim();
PortInfo portInfo = getPortInfo(servletType, bundle, portLocations);
if (portInfo != null) {
LOG.debug("Found POJO Web Service: {}", servletName);
map.put(servletName, portInfo);
}
}
} else {
// partial web.xml, discover all web service classes
Map<String, List<String>> classServletMap = createClassServetMap(webApp);
List<Class> services = WARWebServiceFinder.discoverWebServices(module, bundle, false);
String contextRoot = ((WebModule) module).getContextRoot();
for (Class service : services) {
// skip interfaces and such
if (!JAXWSUtils.isWebService(service)) {
continue;
}
LOG.debug("Discovered POJO Web Service class: {}", service.getName());
List<String> mappedServlets = classServletMap.get(service.getName());
if (mappedServlets == null) {
// no <servlet/> entry, add one
LOG.debug("POJO Web Service class {} is not mapped to any servlet", service.getName());
ServletType servlet = webApp.addNewServlet();
servlet.addNewServletName().setStringValue(service.getName());
servlet.addNewServletClass().setStringValue(service.getName());
String location = (String)portLocations.get(service.getName());
if (location == null) {
// add new <servlet-mapping/> element
location = "/" + JAXWSUtils.getServiceName(service);
ServletMappingType servletMapping = webApp.addNewServletMapping();
servletMapping.addNewServletName().setStringValue(service.getName());
servletMapping.addNewUrlPattern().setStringValue(location);
} else {
// weird, there was no servlet entry for this class but
// servlet-mapping exists
LOG.warn("Found <servlet-mapping> but corresponding <servlet> was not defined");
}
// map service
PortInfo portInfo = new PortInfo();
portInfo.setLocation(contextRoot + location);
map.put(service.getName(), portInfo);
} else {
// found at least one mapped <servlet/> entry
for (String servlet : mappedServlets) {
LOG.debug("POJO Web Service class {} is mapped to {} servlet", service.getName(), servlet);
PortInfo portInfo = createPortInfo(servlet, portLocations);
map.put(servlet, portInfo);
}
}
}
// double check servlets in case we missed something
ServletType[] servletTypes = webApp.getServletArray();
for (ServletType servletType : servletTypes) {
String servletName = servletType.getServletName().getStringValue().trim();
if (map.get(servletName) == null) {
PortInfo portInfo = getPortInfo(servletType, bundle, portLocations);
if (portInfo != null) {
LOG.debug("Found POJO Web Service: {}", servletName);
map.put(servletName, portInfo);
}
}