Skip to content

Commit

Permalink
#6 Endpoint auto initialization is now deactivatable - e.g. for clien…
Browse files Browse the repository at this point in the history
…t only sceanarios (it also helps #8). Renamed the SystemTest from Integration test which it is not.
  • Loading branch information
jonashackt committed Jan 16, 2017
1 parent 8fa1111 commit 42cc719
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -60,11 +61,24 @@ public WebServiceAutoDetector webServiceAutoDetector() throws BootStarterCxfExce
@PostConstruct
public void setUp() throws BootStarterCxfException {
webServiceClient = webServiceAutoDetector().searchAndInstantiateWebServiceClient();
seiImplementation = webServiceAutoDetector().searchAndInstantiateSeiImplementation();
serviceUrlEnding = "/" + webServiceClient().getServiceName().getLocalPart();
}

/*
* We mostly want to autoinitialize the Endpoint and the CXFServlet.
* But when in client mode, this isn´t always wanted (e.g. when you are in Client
* only mode and just want to test or call some SOAP services, but not provide
* services on your own.
*
* Because there is (& sadly will be) no @ConditionalOnMissingProperty in Spring Boot
* (https://github.com/spring-projects/spring-boot/issues/4938), we need to use a workaround.
*
* If endpoint.autoinit is NOT set, Endpoint autoinitialization will run.
* If endpoint.autoinit is set to some other value than false, autoinitialization will also run.
* Only if endpoint.autoinit = false, the autoinitialization isn´t running.
*/
@Bean
@ConditionalOnProperty(name = "endpoint.autoinit", matchIfMissing = true)
public ServletRegistrationBean cxfDispatcherServlet() {
CXFServlet cxfServlet = new CXFServlet();
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new CXFServlet(), baseUrl + "/*");
Expand All @@ -79,16 +93,22 @@ public ServletRegistrationBean cxfDispatcherServlet() {
// If you don´t want to import the cxf.xml-Springbean-Config you have to setUp this Bus for yourself
// <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus" destroy-method="shutdown"/>
@Bean(name = Bus.DEFAULT_BUS_ID)
@ConditionalOnProperty(name = "endpoint.autoinit", matchIfMissing = true)
public SpringBus springBus() {
return new SpringBus();
}

@Bean
@ConditionalOnProperty(name = "endpoint.autoinit", matchIfMissing = true)
public Object seiImplementation() throws BootStarterCxfException {
if(seiImplementation == null) {
seiImplementation = webServiceAutoDetector().searchAndInstantiateSeiImplementation();
}
return seiImplementation;
}

@Bean
@ConditionalOnProperty(name = "endpoint.autoinit", matchIfMissing = true)
public Endpoint endpoint() throws BootStarterCxfException {

LOG.info("Autodetection successful. Initializing javax.xml.ws.Endpoint based on " + seiImplementation().getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package de.codecentric.cxf.configuration;

import javax.annotation.PostConstruct;

import de.codecentric.cxf.logging.soapmsg.SoapMessageLoggingInInterceptor;
import de.codecentric.cxf.logging.soapmsg.SoapMessageLoggingOutInterceptor;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.interceptor.AbstractLoggingInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
* Logging of SoapMessages to e.g. Console. To activate, set property soap.messages.logging=true.
*
Expand All @@ -25,6 +24,7 @@
*/
@Configuration
@Conditional(SoapMessageLoggerConfiguration.SoapMessageLoggerPropertyCondition.class)
@ConditionalOnProperty(name = "endpoint.autoinit", matchIfMissing = true)
public class SoapMessageLoggerConfiguration {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package de.codecentric.cxf.configuration;

import javax.annotation.PostConstruct;
import javax.xml.ws.Endpoint;

import de.codecentric.cxf.xmlvalidation.CustomFaultBuilder;
import de.codecentric.cxf.xmlvalidation.SoapFaultBuilder;
import de.codecentric.cxf.xmlvalidation.XmlValidationInterceptor;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import de.codecentric.cxf.xmlvalidation.CustomFaultBuilder;
import de.codecentric.cxf.xmlvalidation.SoapFaultBuilder;
import de.codecentric.cxf.xmlvalidation.XmlValidationInterceptor;
import javax.annotation.PostConstruct;
import javax.xml.ws.Endpoint;

/**
* Configure extended XML-Schema validation incl. customizing of the responding SoapFaults.
Expand All @@ -26,6 +25,7 @@
*/
@Configuration
@ConditionalOnBean(CustomFaultBuilder.class)
@ConditionalOnProperty(name = "endpoint.autoinit", matchIfMissing = true)
public class XmlValidationConfiguration {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
properties = { "server.port:8087" }
)
public class WeatherServiceEndpointIntegrationTest {
public class WeatherServiceEndpointSystemTest {

@Autowired
private WeatherService weatherServiceClient;
Expand Down

0 comments on commit 42cc719

Please sign in to comment.