/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.csu.sdmx.soap;

import java.io.PrintWriter;
import java.io.StringWriter;
import javax.xml.namespace.QName;
import org.springframework.stereotype.Component;
import org.springframework.ws.soap.SoapFault;
import org.springframework.ws.soap.SoapFaultDetail;
import org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver;

/**
 *
 * @author themi
 */
@Component
public class SoapFaultExceptionResolver extends
        SoapFaultAnnotationExceptionResolver{

    @Override
    protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
        ex.printStackTrace();
        SoapFaultDetail detail = fault.addFaultDetail(); 
        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        detail.addFaultDetailElement(new QName("StackTrace")).addText(sw.toString());
    }
    
}
