private List<EndpointInfo> getConsolidatedEndpoints( ServletContext context, List<EndpointInfo> ddEndpointList, Set<Class<?>> wsClassSet, List<Source> metadata) { List<EndpointInfo> consList = new ArrayList<>(); for (Class<?> c : wsClassSet) { EndpointInfo endpointInfo = findEndpointInfo(ddEndpointList, c); endpointInfo.implType = c; if (endpointInfo.servletLink == null) { endpointInfo.servletLink = getDefaultServletLink(c); } ServletRegistration reg = context.getServletRegistration(endpointInfo.servletLink); if (reg != null) { Collection<String> mappings = reg.getMappings(); if (mappings.isEmpty()) { endpointInfo.urlPattern = getDefaultUrlPattern(c); } else { endpointInfo.urlPattern = mappings.iterator().next(); } } else { endpointInfo.urlPattern = getDefaultUrlPattern(c); } endpointInfo.features = new WebServiceFeature[0]; endpointInfo.metadata = metadata; consList.add(endpointInfo); } return consList; }
public void onStartup(Set<Class<?>> wsClassSet, ServletContext context) throws ServletException { LOGGER.info("WAR has webservice classes: " + wsClassSet); // TODO Check if metadata-complete is true in web.xml // Get the WSDL and schema documents in /WEB-INF/wsdl dir List<Source> metadata = new ArrayList<>(); try { Set<URL> docs = new HashSet<>(); collectDocs(docs, new ServletResourceLoader(context), JAXWS_WSDL_DD_DIR); for (URL url : docs) { Source source = new StreamSource(url.openStream(), url.toExternalForm()); metadata.add(source); } } catch (IOException me) { throw new ServletException(me); } // Parse /WEB-INF/webservices.xml DD List<EndpointInfo> ddEndpointList = parseDD(context); // Consolidate endpoints from DD and annotations List<EndpointInfo> endpointInfoList = getConsolidatedEndpoints(context, ddEndpointList, wsClassSet, metadata); if (endpointInfoList.isEmpty()) { return; // No web service endpoints } EndpointAdapterFactory factory = new EndpointAdapterFactory(); List<EndpointAdapter> adapters = new ArrayList<>(); for (EndpointInfo endpointInfo : endpointInfoList) { ServletRegistration reg = context.getServletRegistration(endpointInfo.servletLink); if (reg == null) { reg = context.addServlet(endpointInfo.servletLink, WSServlet.class); } else { // NEED the following in servlet API to override <servlet-class> // reg.setClassName(endpointInfo.implType); } Collection<String> mappings = reg.getMappings(); if (!mappings.contains(endpointInfo.urlPattern)) { reg.addMapping(endpointInfo.urlPattern); } EndpointAdapter adapter = factory.createAdapter(endpointInfo); adapters.add(adapter); } for (EndpointAdapter adapter : adapters) { adapter.publish(); } context.setAttribute(WSServlet.JAXWS_RI_RUNTIME_INFO, adapters); }