<commit_before>package de.holisticon.util.tracee.jaxws.container;

import de.holisticon.util.tracee.TraceeLogger;
import de.holisticon.util.tracee.contextlogger.connector.ConnectorFactory;
import de.holisticon.util.tracee.contextlogger.json.generator.TraceeContextLoggerJsonCreator;
import de.holisticon.util.tracee.jaxws.AbstractTraceeHandler;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import java.io.ByteArrayOutputStream;
import java.util.Set;

/**
 * JaxWs container side handler that detects uncaught exceptions and outputs contextual informations.
 *
 * @author <NAME> (Holisticon AG)
 */
public class TraceeServerErrorLoggingHandler extends AbstractTraceeHandler {

    private final TraceeLogger traceeLogger = this.getTraceeBackend().getLoggerFactory().getLogger(
			TraceeServerHandler.class);

    private static final ThreadLocal<String> THREAD_LOCAL_SOAP_MESSAGE_STR = new ThreadLocal<String>();

    @Override
    public final boolean handleFault(SOAPMessageContext context) {

        // Must pipe out Soap envelope
        SOAPMessage soapMessage = context.getMessage();

        Object errorJsonCreator = TraceeContextLoggerJsonCreator.createJsonCreator()
                .addPrefixedMessage("TraceeServerErrorLoggingHandler - FAULT :\n ")
                .addJaxwsCategory(THREAD_LOCAL_SOAP_MESSAGE_STR.get(), getSoapMessageAsString(soapMessage))
                .addCommonCategory()
                .addTraceeCategory(getTraceeBackend());

        // write message to connectors
         ConnectorFactory.sendErrorReportToConnectors(errorJsonCreator);

        // cleanup thread local request soap message
        THREAD_LOCAL_SOAP_MESSAGE_STR.remove();

        return true;

    }

    /**
     * Converts a SOAPMessage instance to string representation.
     */
    private String getSoapMessageAsString(SOAPMessage soapMessage) {

        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            soapMessage.writeTo(os);
            return new String(os.toByteArray(), "UTF-8");
        } catch (Exception e) {
            return "ERROR";
        }
    }<commit_msg>fixed cast error.<commit_after>package de.holisticon.util.tracee.jaxws.container;

import de.holisticon.util.tracee.TraceeLogger;
import de.holisticon.util.tracee.contextlogger.connector.ConnectorFactory;
import de.holisticon.util.tracee.contextlogger.connector.PrintableByConnector;
import de.holisticon.util.tracee.contextlogger.json.generator.TraceeContextLoggerJsonCreator;
import de.holisticon.util.tracee.jaxws.AbstractTraceeHandler;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import java.io.ByteArrayOutputStream;
import java.util.Set;

/**
 * JaxWs container side handler that detects uncaught exceptions and outputs contextual informations.
 *
 * @author <NAME> (Holisticon AG)
 */
public class TraceeServerErrorLoggingHandler extends AbstractTraceeHandler {

    private final TraceeLogger traceeLogger = this.getTraceeBackend().getLoggerFactory().getLogger(
			TraceeServerHandler.class);

    private static final ThreadLocal<String> THREAD_LOCAL_SOAP_MESSAGE_STR = new ThreadLocal<String>();

    @Override
    public final boolean handleFault(SOAPMessageContext context) {

        // Must pipe out Soap envelope
        SOAPMessage soapMessage = context.getMessage();

        PrintableByConnector errorJsonCreator = TraceeContextLoggerJsonCreator.createJsonCreator()
                .addPrefixedMessage("TraceeServerErrorLoggingHandler - FAULT :\n ")
                .addJaxwsCategory(THREAD_LOCAL_SOAP_MESSAGE_STR.get(), getSoapMessageAsString(soapMessage))
                .addCommonCategory()
                .addTraceeCategory(getTraceeBackend());

        // write message to connectors
         ConnectorFactory.sendErrorReportToConnectors(errorJsonCreator);

        // cleanup thread local request soap message
        THREAD_LOCAL_SOAP_MESSAGE_STR.remove();

        return true;

    }

    /**
     * Converts a SOAPMessage instance to string representation.
     */
    private String getSoapMessageAsString(SOAPMessage soapMessage) {

        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            soapMessage.writeTo(os);
            return new String(os.toByteArray(), "UTF-8");
        } catch (Exception e) {
            return "ERROR";
        }
    }
{'fraction_non_alphanumeric': 0.0832035595105673, 'fraction_numerical': 0.0004449388209121246, 'mean_word_length': 3.625514403292181, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '988439', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1205, 'n_words': 240}