// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/configuration/customsoapfaults/CustomSoapFaultInterceptor.java
// 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);
// 	    	WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SCHEME_VALIDATION_ERROR);
// 	    } else if (containsFaultIndicatingSyntacticallyIncorrectXml(faultCause)) {
// 	    	LOG.schemaValidationError(FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR, faultMessage);
// 	    	WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR);	        
// 	    }
// 	}
// 
// 	private boolean containsFaultIndicatingNotSchemeCompliantXml(Throwable faultCause, String faultMessage) {
// 		if(faultCause instanceof UnmarshalException
// 	    	// 1.) If the root-Element of the SoapBody is syntactically correct, but not scheme-compliant,
// 			// 		there is no UnmarshalException and we have to look for
// 			// 2.) Missing / lead to Faults without Causes, but to Messages like "Unexpected wrapper element XYZ found. Expected"
// 			// 		One could argue, that this is syntactically incorrect, but here we just take it as Non-Scheme-compliant
// 	    	|| isNotNull(faultMessage) && faultMessage.contains("Unexpected wrapper element")) {
// 			return true;
// 		}
// 		return false;
// 	}
// 	
// 	private boolean containsFaultIndicatingSyntacticallyIncorrectXml(Throwable faultCause) {
// 		if(faultCause instanceof WstxException
// 			// If Xml-Header is invalid, there is a wrapped Cause in the original Cause we have to check
// 			|| isNotNull(faultCause) && faultCause.getCause() instanceof WstxUnexpectedCharException
// 	    	|| faultCause instanceof IllegalArgumentException) {
// 			return true;
// 		}
// 		return false;
// 	}
// 	
// 	private boolean isNotNull(Object object) {
// 		return object != null;
// 	}
// }
// 
// Path: step3_jaxws-endpoint-cxf-spring-boot/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java
// public class WeatherServiceEndpoint implements WeatherService {
// 
//     @Override
//     public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest)
//             throws WeatherException {
//         // TODO Auto-generated method stub
//         return null;
//     }
//     
//     @Override
//     public WeatherInformationReturn getWeatherInformation(String zip)
//             throws WeatherException {
//         // TODO Auto-generated method stub
//         return null;
//     }
// 
//     @Override
//     public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest)
//             throws WeatherException {
//         // TODO Auto-generated method stub
//         return null;
//     }
// 
// }


import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import de.codecentric.namespace.weatherservice.Weather;
import de.codecentric.namespace.weatherservice.WeatherService;
import de.jonashackt.tutorial.configuration.customsoapfaults.CustomSoapFaultInterceptor;
import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint;
package de.jonashackt.tutorial.configuration;




@Configuration
public class WebServiceConfiguration {
	
    public static final String BASE_URL = "/soap-api";
    public static final String SERVICE_URL = "/WeatherSoapService_1.0";
    
    @Bean
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), BASE_URL + "/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }    
    
    @Bean
    public WeatherService weatherService() {
// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/configuration/customsoapfaults/CustomSoapFaultInterceptor.java
// 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);
// 	    	WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SCHEME_VALIDATION_ERROR);
// 	    } else if (containsFaultIndicatingSyntacticallyIncorrectXml(faultCause)) {
// 	    	LOG.schemaValidationError(FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR, faultMessage);
// 	    	WeatherSoapFaultHelper.buildWeatherFaultAndSet2SoapMessage(soapMessage, FaultConst.SYNTACTICALLY_INCORRECT_XML_ERROR);	        
// 	    }
// 	}
// 
// 	private boolean containsFaultIndicatingNotSchemeCompliantXml(Throwable faultCause, String faultMessage) {
// 		if(faultCause instanceof UnmarshalException
// 	    	// 1.) If the root-Element of the SoapBody is syntactically correct, but not scheme-compliant,
// 			// 		there is no UnmarshalException and we have to look for
// 			// 2.) Missing / lead to Faults without Causes, but to Messages like "Unexpected wrapper element XYZ found. Expected"
// 			// 		One could argue, that this is syntactically incorrect, but here we just take it as Non-Scheme-compliant
// 	    	|| isNotNull(faultMessage) && faultMessage.contains("Unexpected wrapper element")) {
// 			return true;
// 		}
// 		return false;
// 	}
// 	
// 	private boolean containsFaultIndicatingSyntacticallyIncorrectXml(Throwable faultCause) {
// 		if(faultCause instanceof WstxException
// 			// If Xml-Header is invalid, there is a wrapped Cause in the original Cause we have to check
// 			|| isNotNull(faultCause) && faultCause.getCause() instanceof WstxUnexpectedCharException
// 	    	|| faultCause instanceof IllegalArgumentException) {
// 			return true;
// 		}
// 		return false;
// 	}
// 	
// 	private boolean isNotNull(Object object) {
// 		return object != null;
// 	}
// }
// 
// Path: step3_jaxws-endpoint-cxf-spring-boot/src/main/java/de/jonashackt/tutorial/endpoint/WeatherServiceEndpoint.java
// public class WeatherServiceEndpoint implements WeatherService {
// 
//     @Override
//     public ForecastReturn getCityForecastByZIP(ForecastRequest forecastRequest)
//             throws WeatherException {
//         // TODO Auto-generated method stub
//         return null;
//     }
//     
//     @Override
//     public WeatherInformationReturn getWeatherInformation(String zip)
//             throws WeatherException {
//         // TODO Auto-generated method stub
//         return null;
//     }
// 
//     @Override
//     public WeatherReturn getCityWeatherByZIP(ForecastRequest forecastRequest)
//             throws WeatherException {
//         // TODO Auto-generated method stub
//         return null;
//     }
// 
// }


// Path: step5_custom-soap-fault/src/main/java/de/jonashackt/tutorial/configuration/WebServiceConfiguration.java
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import de.codecentric.namespace.weatherservice.Weather;
import de.codecentric.namespace.weatherservice.WeatherService;
import de.jonashackt.tutorial.configuration.customsoapfaults.CustomSoapFaultInterceptor;
import de.jonashackt.tutorial.endpoint.WeatherServiceEndpoint;

package de.jonashackt.tutorial.configuration;




@Configuration
public class WebServiceConfiguration {
	
    public static final String BASE_URL = "/soap-api";
    public static final String SERVICE_URL = "/WeatherSoapService_1.0";
    
    @Bean
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), BASE_URL + "/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }    
    
    @Bean
    public WeatherService weatherService() {
    	return new WeatherServiceEndpoint();