// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/common/FaultConst.java
// public enum FaultConst {
// 
// 	SUCCESSFULL_PROCESSING("01", "The Weather-Call was successfully processed by the backend."),
// 	SCHEME_VALIDATION_ERROR("07", "XML-Scheme-validiation failed."),
// 	SYNTACTICALLY_INCORRECT_XML_ERROR("08", "Syntactically incorrect XML."),	
// 	BACKEND_PROCESSING_FAILED("04", "Backend processing failed.");
// 
// 	private String id;
// 	private String message;
// 	
// 	private FaultConst(String id, String text) {
// 		this.id = id;
// 		this.message = text;
// 	}
// 	
// 	public String getMessage() {
// 		return message;
// 	}
// 	
// 	public String getId() {
// 		return id;
// 	}
// 	
// }
// 
// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/logging/SoapFrameworkLogger.java
// public class SoapFrameworkLogger {
//     
// 	private Logger delegateLogger;
// 	
// 	private SoapFrameworkLogger() {};
// 	
// 	public static <L> SoapFrameworkLogger getLogger(Class<L> class2LogFor) {
// 		SoapFrameworkLogger frameworkLogger = new SoapFrameworkLogger();
// 		frameworkLogger.delegateLogger = LoggerFactory.getLogger(class2LogFor);
// 		return frameworkLogger;
// 	}	
// 	
// 	/*
// 	 * Errors - 9xx
// 	 */
// 	public void errorAccuredInBackendProcessing(Throwable cause) {
// 		logError("901", "An Error accured in backend-processing: {}", cause.getMessage());
// 	}
// 	
// 	public void failedToBuildWeatherServiceCompliantSoapFaultDetails(Throwable cause) {
// 		logError("902", "Failed to build Weather-compliant SoapFault-details: {}\nStacktrace: {}", cause.getMessage(), cause.getStackTrace());
// 	}	
// 	
// 	public void schemaValidationError(FaultConst error, String faultMessage) {
// 		logDebug("903", error.getMessage() + ": {}", faultMessage);
// 	}
// 	
// 
// 	/*
// 	 * Logger-Methods - only private, to use just inside this class
// 	 */
// 
// 	private void logDebug(String id, String messageTemplate, Object... parameters) {
// 		String msg = formatMessage(id, messageTemplate);
// 		delegateLogger.debug(msg, parameters);
// 	}
// 	
// 	private void logError(String id, String messageTemplate, Object... parameters) {
// 		String msg = formatMessage(id, messageTemplate);
// 		delegateLogger.error(msg, parameters);
// 	}
// 	
// 	private String formatMessage(String id, String messageTemplate) {
// 		return id + " >>> " + messageTemplate;
// 	}
// 	
// }


import javax.xml.bind.UnmarshalException;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase;
import com.ctc.wstx.exc.WstxException;
import com.ctc.wstx.exc.WstxUnexpectedCharException;
import de.jonashackt.tutorial.common.FaultConst;
import de.jonashackt.tutorial.logging.SoapFrameworkLogger;
package de.jonashackt.tutorial.configuration.customsoapfaults;






public class CustomSoapFaultInterceptor extends AbstractSoapInterceptor {

	private static final SoapFrameworkLogger LOG = SoapFrameworkLogger.getLogger(CustomSoapFaultInterceptor.class);
	
	public CustomSoapFaultInterceptor() {
		super(Phase.PRE_STREAM);
	}
	
	@Override
	public void handleMessage(SoapMessage soapMessage) throws Fault {
	    Fault fault = (Fault) soapMessage.getContent(Exception.class);
	    Throwable faultCause = fault.getCause();
	    String faultMessage = fault.getMessage();

	    if (containsFaultIndicatingNotSchemeCompliantXml(faultCause, faultMessage)) { 
// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/common/FaultConst.java
// public enum FaultConst {
// 
// 	SUCCESSFULL_PROCESSING("01", "The Weather-Call was successfully processed by the backend."),
// 	SCHEME_VALIDATION_ERROR("07", "XML-Scheme-validiation failed."),
// 	SYNTACTICALLY_INCORRECT_XML_ERROR("08", "Syntactically incorrect XML."),	
// 	BACKEND_PROCESSING_FAILED("04", "Backend processing failed.");
// 
// 	private String id;
// 	private String message;
// 	
// 	private FaultConst(String id, String text) {
// 		this.id = id;
// 		this.message = text;
// 	}
// 	
// 	public String getMessage() {
// 		return message;
// 	}
// 	
// 	public String getId() {
// 		return id;
// 	}
// 	
// }
// 
// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/logging/SoapFrameworkLogger.java
// public class SoapFrameworkLogger {
//     
// 	private Logger delegateLogger;
// 	
// 	private SoapFrameworkLogger() {};
// 	
// 	public static <L> SoapFrameworkLogger getLogger(Class<L> class2LogFor) {
// 		SoapFrameworkLogger frameworkLogger = new SoapFrameworkLogger();
// 		frameworkLogger.delegateLogger = LoggerFactory.getLogger(class2LogFor);
// 		return frameworkLogger;
// 	}	
// 	
// 	/*
// 	 * Errors - 9xx
// 	 */
// 	public void errorAccuredInBackendProcessing(Throwable cause) {
// 		logError("901", "An Error accured in backend-processing: {}", cause.getMessage());
// 	}
// 	
// 	public void failedToBuildWeatherServiceCompliantSoapFaultDetails(Throwable cause) {
// 		logError("902", "Failed to build Weather-compliant SoapFault-details: {}\nStacktrace: {}", cause.getMessage(), cause.getStackTrace());
// 	}	
// 	
// 	public void schemaValidationError(FaultConst error, String faultMessage) {
// 		logDebug("903", error.getMessage() + ": {}", faultMessage);
// 	}
// 	
// 
// 	/*
// 	 * Logger-Methods - only private, to use just inside this class
// 	 */
// 
// 	private void logDebug(String id, String messageTemplate, Object... parameters) {
// 		String msg = formatMessage(id, messageTemplate);
// 		delegateLogger.debug(msg, parameters);
// 	}
// 	
// 	private void logError(String id, String messageTemplate, Object... parameters) {
// 		String msg = formatMessage(id, messageTemplate);
// 		delegateLogger.error(msg, parameters);
// 	}
// 	
// 	private String formatMessage(String id, String messageTemplate) {
// 		return id + " >>> " + messageTemplate;
// 	}
// 	
// }


// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/configuration/customsoapfaults/CustomSoapFaultInterceptor.java
import javax.xml.bind.UnmarshalException;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase;
import com.ctc.wstx.exc.WstxException;
import com.ctc.wstx.exc.WstxUnexpectedCharException;
import de.jonashackt.tutorial.common.FaultConst;
import de.jonashackt.tutorial.logging.SoapFrameworkLogger;

package de.jonashackt.tutorial.configuration.customsoapfaults;






public class CustomSoapFaultInterceptor extends AbstractSoapInterceptor {

	private static final SoapFrameworkLogger LOG = SoapFrameworkLogger.getLogger(CustomSoapFaultInterceptor.class);
	
	public CustomSoapFaultInterceptor() {
		super(Phase.PRE_STREAM);
	}
	
	@Override
	public void handleMessage(SoapMessage soapMessage) throws Fault {
	    Fault fault = (Fault) soapMessage.getContent(Exception.class);
	    Throwable faultCause = fault.getCause();
	    String faultMessage = fault.getMessage();

	    if (containsFaultIndicatingNotSchemeCompliantXml(faultCause, faultMessage)) { 
	    	LOG.schemaValidationError(FaultConst.SCHEME_VALIDATION_ERROR, faultMessage);