<commit_before>package org.drools.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.drools.Person;
import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.StatelessSession;
import org.drools.common.InternalRuleBase;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;

public class RuleService extends HttpServlet {


	static XStream xmlInstance = configureXStream(false);
	static XStream jsonInstance = configureXStream(true);


	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse resp)
			throws ServletException, IOException {

		String uri = request.getRequestURI();
		RuleBase rb =  getRuleBaseFromURI(uri);

		//doService(request.getInputStream(), resp.getOutputStream(), rb);


		//sample();


	}

	void doService(InputStream inputStream,
			OutputStream outputStream, RuleBase rb, boolean json) {
		InternalRuleBase irb = (InternalRuleBase) rb;
		ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
		try {
			ClassLoader cl = irb.getCompositePackageClassLoader();
			Thread.currentThread().setContextClassLoader(cl);

			XStream xs = (json) ? jsonInstance : xmlInstance;
			ServiceRequestMessage req = (ServiceRequestMessage) xs.fromXML(inputStream);
			StatelessSession session  = rb.newStatelessSession();
			if (req.globals != null) {
				for (NamedFact nf : req.globals) {
					session.setGlobal(nf.id, nf.fact);
				}
			}
			List<Object> facts = new ArrayList<Object>();
			if (req.inFacts != null) {
				for (AnonFact f : req.inFacts) {
					facts.add(f.fact);<commit_msg>moving to root classloader<commit_after>package org.drools.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.drools.Person;
import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.StatelessSession;
import org.drools.common.InternalRuleBase;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;

public class RuleService extends HttpServlet {


	static XStream xmlInstance = configureXStream(false);
	static XStream jsonInstance = configureXStream(true);


	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse resp)
			throws ServletException, IOException {

		String uri = request.getRequestURI();
		RuleBase rb =  getRuleBaseFromURI(uri);

		//doService(request.getInputStream(), resp.getOutputStream(), rb);


		//sample();


	}

	void doService(InputStream inputStream,
			OutputStream outputStream, RuleBase rb, boolean json) {
		InternalRuleBase irb = (InternalRuleBase) rb;
		ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
		try {
			ClassLoader cl = irb.getRootClassLoader();
			Thread.currentThread().setContextClassLoader(cl);

			XStream xs = (json) ? jsonInstance : xmlInstance;
			ServiceRequestMessage req = (ServiceRequestMessage) xs.fromXML(inputStream);
			StatelessSession session  = rb.newStatelessSession();
			if (req.globals != null) {
				for (NamedFact nf : req.globals) {
					session.setGlobal(nf.id, nf.fact);
				}
			}
			List<Object> facts = new ArrayList<Object>();
			if (req.inFacts != null) {
				for (AnonFact f : req.inFacts) {
					facts.add(f.fact);
{'fraction_non_alphanumeric': 0.10295230885692658, 'fraction_numerical': 0.0, 'mean_word_length': 5.252365930599369, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2495420', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1150, 'n_words': 252}