Skip to content

Instantly share code, notes, and snippets.

View jonashackt's full-sized avatar
:octocat:
TDD & CI for IaC FTW!

Jonas Hecht jonashackt

:octocat:
TDD & CI for IaC FTW!
View GitHub Profile
@jonashackt
jonashackt / Namespace.java
Created May 5, 2015 12:17
Get the Namespace-Uri from JAXB-Class-Declaration
public static <T> String getNamespaceUriFromJaxbClass(Class<T> jaxbClass) {
String nsURI = "";
for(Annotation annotation: jaxbClass.getPackage().getAnnotations()){
if(annotation.annotationType() == XmlSchema.class){
nsURI = ((XmlSchema)annotation).namespace();
break;
}
}
return nsURI;
}
@jonashackt
jonashackt / Application.java
Last active August 29, 2015 14:20
Deploying Spring Boot as fat war
// The inheritance of SpringBootServletInitializer is necessary for the war-Deployment-ability
@ComponentScan("de.codecentric.somepackage")
@EnableAutoConfiguration
@Configuration
public class Application extends SpringBootServletInitializer {
private static Class<Application> applicationClass = Application.class;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
@jonashackt
jonashackt / pom.xml
Created May 6, 2015 13:43
Deploying Spring Boot as fat war Part 2
<packaging>war</packaging>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring-boot-version}</version>
<!-- war/Tomcat-Deployment - change deployment from pom to war -->
<scope>provided</scope>
</dependency>
...
@jonashackt
jonashackt / console.log
Created May 7, 2015 09:26
Spring Boot Standard Banner
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.3.RELEASE)
@jonashackt
jonashackt / console.log
Created May 7, 2015 09:38
Custom Spring Boot Banner
______ ______ ______ __ __ __ ______ __ __
/\ ___\ /\ __ \ /\ __ \ /\ \ /\ "-.\ \ /\ ___\ /\ \ _ \ \
\ \ \____ \ \ \/\ \ \ \ \/\ \ \ \ \____ \ \ \-. \ \ \ __\ \ \ \/ ".\ \
\ \_____\ \ \_____\ \ \_____\ \ \_____\ \ \_\\"\_\ \ \_____\ \ \__/".~\_\
\/_____/ \/_____/ \/_____/ \/_____/ \/_/ \/_/ \/_____/ \/_/ \/_/
__ __ __ ______ ______ ______ ______ ______ ______ __ __ __ ______ ______
/\ "-./ \ /\ \ /\ ___\ /\ == \ /\ __ \ /\ ___\ /\ ___\ /\ == \ /\ \ / / /\ \ /\ ___\ /\ ___
@jonashackt
jonashackt / MockTest.java
Created May 11, 2015 07:10
REST Mocktest with Spring MockRestServiceServer and RestTemplate
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
@jonashackt
jonashackt / Service.wsdl
Created May 12, 2015 08:45
Define Custom Exception in WSDL (import the Exception Definition from another XSD - not included here)
<!-- ... -->
<wsdl:message name="WeatherException">
<wsdl:part name="parameters" element="datatypes:WeatherException" />
</wsdl:message>
<!-- ... -->
<wsdl:portType name="WeatherSoap">
<wsdl:operation name="GetWeatherInformation">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Gets Information for each WeatherID</wsdl:documentation>
<wsdl:input message="tns:GetWeatherInformationSoapIn"/>
<wsdl:output message="tns:GetWeatherInformationSoapOut"/>
@jonashackt
jonashackt / WeatherServiceXmlValidationInterceptor.java
Created May 13, 2015 15:28
Apache CXF Interceptor for Custom SoapFaults
public class WeatherServiceXmlValidationInterceptor extends AbstractSoapInterceptor {
//...
public WeatherServiceXmlValidationInterceptor() {
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage(SoapMessage soapMessage) throws Fault {
Fault fault = (Fault) soapMessage.getContent(Exception.class);
@jonashackt
jonashackt / WeatherServiceXmlValidationInterceptor.java
Created May 13, 2015 15:44
Apache CXF Interceptor for Custom SoapFaults Part 2. - Checking for relevant Exceptions
//...
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;
}
@jonashackt
jonashackt / MarhallJaxbElement.java
Last active August 29, 2015 14:21
Marhall an JAXBObject into org.w3c.dom.Document
public static Document marhallJaxbElement(Object jaxbElement) throws BusinessException {
Document jaxbDoc = null;
try {
Marshaller marshaller = setUpMarshaller(jaxbElement.getClass());
jaxbDoc = createNewDocument();
marshaller.marshal(jaxbElement, jaxbDoc);
} catch (Exception exception) {
throw new BusinessException("Problem beim marshallen des JAXBElements in ein Document: " + exception.getMessage());
}
return jaxbDoc;