<commit_before>package org.kantega.reststop.cxf;

import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.apache.cxf.wsdl.WSDLManager;
import org.kantega.reststop.api.*;
import org.kantega.reststop.jaxwsapi.EndpointConfiguration;
import org.kantega.reststop.jaxwsapi.EndpointConfigurationBuilder;
import org.kantega.reststop.jaxwsapi.JaxWsPlugin;
import org.kantega.reststop.cxf.api.CxfPluginPlugin;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.wsdl.Definition;
import javax.xml.ws.Endpoint;
import java.io.IOException;
import java.util.*;

/**
 *
 */
public class CxfReststopPlugin extends DefaultReststopPlugin {


    private final ReststopPluginManager pluginManager;
    private List<Endpoint> endpoints = new ArrayList<>();

    public static ThreadLocal<ClassLoader> pluginClassLoader = new ThreadLocal<>();

    public CxfReststopPlugin(Reststop reststop, final ReststopPluginManager pluginManager, ServletContext servletContext) throws ServletException {
        this.pluginManager = pluginManager;

        CXFNonSpringServlet cxfNonSpringServlet = new CXFNonSpringServlet();
        cxfNonSpringServlet.init(reststop.createServletConfig("cxf", new Properties()));


        addServletFilter(reststop.createServletFilter(cxfNonSpringServlet, "/ws*"));

        addPluginListener(new PluginListener() {
            @Override
            public void pluginsUpdated(Collection<ReststopPlugin> plugins) {
                deployEndpoints();
            }

            @Override
            public void pluginManagerStarted() {
                deployEndpoints();
            }
        });

        addService(EndpointConfigurationBuilder.class, new DefaultEndpointConfigurationBuilder());
    }

    private void deployEndpoints() {
        for (Endpoint endpoint : endpoints) {
            endpoint.stop();
        }

        WSDLManager wsdlManager = WSDLManagerDefinitionCacheCleaner.getWsdlManager();
        for (Definition def : wsdlManager.getDefinitions().values()) {
            wsdlManager.removeDefinition(def);
        }
        for (JaxWsPlugin plugin : pluginManager.getPlugins(JaxWsPlugin.class)) {

            try {
                pluginClassLoader.set(pluginManager.getClassLoader(plugin));

                for (EndpointConfiguration config : plugin.getEndpointConfigurations()) {
                    Endpoint endpoint = Endpoint.create(config.getImplementor());
                    endpoint.publish(config.getPath());
                    for (CxfPluginPlugin cxfPluginPlugin : pluginManager.getPlugins(CxfPluginPlugin.class)) {
                        cxfPluginPlugin.customizeEndpoint(endpoint);
                    }
                    CxfReststopPlugin.this.endpoints.add(endpoint);
                }
            } finally {
                pluginClassLoader.remove();
            }
        }

    }

    private class DefaultEndpointConfigurationBuilder implements EndpointConfigurationBuilder {

        @Override
        public Build service(Object service) {
            return new DefaultBuild(service);
        }
        private class DefaultBuild implements Build {
            private final Object service;
            private String path;

            public DefaultBuild(Object service) {
                this.service = service;
            }

            @Override
            public Build path(String path) {
                this.path = path;
                return this;
            }

            @Override
            public EndpointConfiguration build() {
                return new EndpointConfiguration() {
                    @Override
                    public Object getImplementor() {
                        return service;
                    }

                    @Override
                    public String getPath() {
                        return path;
                    }
                };
            }

        }
    }
}
<commit_msg>Don't swallow everything /ws*<commit_after>package org.kantega.reststop.cxf;

import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.apache.cxf.wsdl.WSDLManager;
import org.kantega.reststop.api.*;
import org.kantega.reststop.jaxwsapi.EndpointConfiguration;
import org.kantega.reststop.jaxwsapi.EndpointConfigurationBuilder;
import org.kantega.reststop.jaxwsapi.JaxWsPlugin;
import org.kantega.reststop.cxf.api.CxfPluginPlugin;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.wsdl.Definition;
import javax.xml.ws.Endpoint;
import java.io.IOException;
import java.util.*;

/**
 *
 */
public class CxfReststopPlugin extends DefaultReststopPlugin {


    private final ReststopPluginManager pluginManager;
    private List<Endpoint> endpoints = new ArrayList<>();

    public static ThreadLocal<ClassLoader> pluginClassLoader = new ThreadLocal<>();

    public CxfReststopPlugin(Reststop reststop, final ReststopPluginManager pluginManager, ServletContext servletContext) throws ServletException {
        this.pluginManager = pluginManager;

        CXFNonSpringServlet cxfNonSpringServlet = new CXFNonSpringServlet();
        cxfNonSpringServlet.init(reststop.createServletConfig("cxf", new Properties()));


        addServletFilter(reststop.createServletFilter(cxfNonSpringServlet, "/ws/*"));

        addPluginListener(new PluginListener() {
            @Override
            public void pluginsUpdated(Collection<ReststopPlugin> plugins) {
                deployEndpoints();
            }

            @Override
            public void pluginManagerStarted() {
                deployEndpoints();
            }
        });

        addService(EndpointConfigurationBuilder.class, new DefaultEndpointConfigurationBuilder());
    }

    private void deployEndpoints() {
        for (Endpoint endpoint : endpoints) {
            endpoint.stop();
        }

        WSDLManager wsdlManager = WSDLManagerDefinitionCacheCleaner.getWsdlManager();
        for (Definition def : wsdlManager.getDefinitions().values()) {
            wsdlManager.removeDefinition(def);
        }
        for (JaxWsPlugin plugin : pluginManager.getPlugins(JaxWsPlugin.class)) {

            try {
                pluginClassLoader.set(pluginManager.getClassLoader(plugin));

                for (EndpointConfiguration config : plugin.getEndpointConfigurations()) {
                    Endpoint endpoint = Endpoint.create(config.getImplementor());
                    endpoint.publish(config.getPath());
                    for (CxfPluginPlugin cxfPluginPlugin : pluginManager.getPlugins(CxfPluginPlugin.class)) {
                        cxfPluginPlugin.customizeEndpoint(endpoint);
                    }
                    CxfReststopPlugin.this.endpoints.add(endpoint);
                }
            } finally {
                pluginClassLoader.remove();
            }
        }

    }

    private class DefaultEndpointConfigurationBuilder implements EndpointConfigurationBuilder {

        @Override
        public Build service(Object service) {
            return new DefaultBuild(service);
        }
        private class DefaultBuild implements Build {
            private final Object service;
            private String path;

            public DefaultBuild(Object service) {
                this.service = service;
            }

            @Override
            public Build path(String path) {
                this.path = path;
                return this;
            }

            @Override
            public EndpointConfiguration build() {
                return new EndpointConfiguration() {
                    @Override
                    public Object getImplementor() {
                        return service;
                    }

                    @Override
                    public String getPath() {
                        return path;
                    }
                };
            }

        }
    }
}

{'fraction_non_alphanumeric': 0.07901538461538461, 'fraction_numerical': 0.0, 'mean_word_length': 2.17670054730258, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5453606', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1870, 'n_words': 373}