public synchronized void init(ServletConfig servletConfig) throws ServletException { if (delegate != null) { return; } super.init(servletConfig); ServletContext servletContext = servletConfig.getServletContext(); // Setup the WSIT endpoint that handles WS-MEX requests for registered endpoints. The TCCL must // be set for JAXB. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader seiClassLoader = MEXEndpoint.class.getClassLoader(); try { Thread.currentThread().setContextClassLoader(seiClassLoader); container = new F3Container(servletContext); WSBinding binding = BindingImpl.create(BindingID.SOAP12_HTTP); mexEndpoint = WSEndpoint.create( MEXEndpoint.class, false, null, null, null, container, binding, null, null, null, true); } finally { Thread.currentThread().setContextClassLoader(classLoader); } // register services for (EndpointConfiguration configuration : configurations) { registerService(configuration); } }
public synchronized void registerService(EndpointConfiguration configuration) { if (delegate == null) { // servlet has not be initialized, delay service registration configurations.add(configuration); return; } Class<?> seiClass = configuration.getSeiClass(); ClassLoader classLoader = seiClass.getClassLoader(); ClassLoader old = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); URL wsdlLocation = configuration.getWsdlLocation(); SDDocumentSource primaryWsdl = null; if (wsdlLocation != null) { // WSDL may not be defined for a Java-based endpoint, in which case it will be introspected // from the SEI class primaryWsdl = SDDocumentSource.create(wsdlLocation); } WSBinding binding = BindingImpl.create(BindingID.SOAP11_HTTP); Container endpointContainer = container; List<SDDocumentSource> metadata = null; URL generatedWsdl = configuration.getGeneratedWsdl(); if (generatedWsdl != null) { // create a container wrapper used by Metro to resolve the WSIT configuration endpointContainer = new WsitConfigurationContainer(container, generatedWsdl); // Compile the list of imported schemas so they can be resolved using ?xsd GET requests. // Metro will re-write the WSDL import // so clients can dereference the imports when they obtain the WSDL. metadata = new ArrayList<>(); List<URL> schemas = configuration.getGeneratedSchemas(); if (schemas != null) { for (URL schema : schemas) { metadata.add(SDDocumentSource.create(schema)); } } } String servicePath = configuration.getServicePath(); Invoker invoker = configuration.getInvoker(); QName serviceName = configuration.getServiceName(); QName portName = configuration.getPortName(); // Fetch the handlers loadHandlers(binding, configuration); WSEndpoint<?> wsEndpoint; try { wsEndpoint = WSEndpoint.create( seiClass, false, invoker, serviceName, portName, endpointContainer, binding, primaryWsdl, metadata, null, true); } catch (WebServiceException e) { if (e.getMessage().contains("Not a primary WSDL")) { // workaround for WSDLs without service declarations wsEndpoint = WSEndpoint.create( seiClass, false, invoker, serviceName, portName, endpointContainer, binding, null, metadata, null, true); } else { throw e; } } wsEndpoint.setExecutor(executorService); ServletAdapter adapter = servletAdapterFactory.createAdapter(servicePath, servicePath, wsEndpoint); delegate.registerServletAdapter(adapter, F3Provider.class.getClassLoader()); String mexPath = servicePath + MEX_SUFFIX; ServletAdapter mexAdapter = servletAdapterFactory.createAdapter(mexPath, mexPath, mexEndpoint); delegate.registerServletAdapter(mexAdapter, F3Provider.class.getClassLoader()); } finally { Thread.currentThread().setContextClassLoader(old); } }