Skip to content

Commit

Permalink
#6 Autodetection is now done in the PostConstruction-Stage of the Cxf…
Browse files Browse the repository at this point in the history
…AutoConfiguration - so the Autodetection is only done once and if it fails, it will fail fast. Also the Logging is enhanced, so you can see the Endpoint initializing better. Also some getters renamed and used inside CxfAutoConfiguration.
  • Loading branch information
jonashackt committed Nov 22, 2016
1 parent e7f5efd commit 13e7b72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
Expand Down Expand Up @@ -41,18 +43,29 @@
})
public class CxfAutoConfiguration {

private static final Logger LOG = LoggerFactory.getLogger(CxfAutoConfiguration.class);

@Value("${soap.service.base.url:/soap-api}")
private String baseUrl;

@Value("${cxf.servicelist.title:CXF SpringBoot Starter - service list}")
private String serviceListTitle;

private String serviceUrlEnding = "";
private Object seiImplementation;
private Service webServiceClient;

private WebServiceAutoDetector webServiceAutoDetector = new WebServiceAutoDetector(new WebServiceScanner());;
private String serviceUrlEnding = "";

@PostConstruct
public void setUp() throws BootStarterCxfException {
// Try to autodetect all necessary classes for Endpoint initialization
WebServiceAutoDetector webServiceAutoDetector = new WebServiceAutoDetector(new WebServiceScanner());

Class serviceEndpointInterface = webServiceAutoDetector.searchServiceEndpointInterface();
seiImplementation = webServiceAutoDetector.searchAndInstantiateSeiImplementation(serviceEndpointInterface);

webServiceClient = webServiceAutoDetector.searchAndInstantiateWebServiceClient();

serviceUrlEnding = "/" + webServiceClient().getServiceName().getLocalPart();
}

Expand All @@ -77,12 +90,14 @@ public SpringBus springBus() {

@Bean
public Object seiImplementation() throws BootStarterCxfException {
Class serviceEndpointInterface = webServiceAutoDetector.searchServiceEndpointInterface();
return webServiceAutoDetector.searchAndInstantiateSeiImplementation(serviceEndpointInterface);
return seiImplementation;
}

@Bean
public Endpoint endpoint() throws BootStarterCxfException {

LOG.info("Autodetection successful. Initializing javax.xml.ws.Endpoint based on " + seiImplementation().getClass().getName());

EndpointImpl endpoint = new EndpointImpl(springBus(), seiImplementation());
// CXF JAX-WS implementation relies on the correct ServiceName as QName-Object with
// the name-Attribute´s text <wsdl:service name="Weather"> and the targetNamespace
Expand All @@ -91,28 +106,28 @@ public Endpoint endpoint() throws BootStarterCxfException {
endpoint.setServiceName(webServiceClient().getServiceName());
endpoint.setWsdlLocation(webServiceClient().getWSDLDocumentLocation().toString());
// publish the Service under it´s name mentioned in the WSDL inside name attribute (example: <wsdl:service name="Weather">)
endpoint.publish(serviceUrlEnding);
endpoint.publish(serviceUrlEnding());
return endpoint;
}

@Bean
public Service webServiceClient() throws BootStarterCxfException {
// Needed for correct ServiceName & WSDLLocation to publish contract first incl. original WSDL
return webServiceAutoDetector.searchAndInstantiateWebServiceClient();
return webServiceClient;
}

/**
* @return the base-URL, where the WebServices are configured (eihter via property or default-value)
*/
public String getBaseUrl() {
public String baseUrl() {
return baseUrl;
}

/**
* @return the concrete Service URL-ending, where the WebService is configured according to your WSDL´s Service Name
* (e.g. &quot;/Weather&quot; when there is this inside your WSDL: &lt;wsdl:service name=&quot;Weather&quot;&gt;)
*/
public String getServiceUrlEnding() {
public String serviceUrlEnding() {
return serviceUrlEnding;
}

Expand All @@ -121,8 +136,8 @@ public String getServiceUrlEnding() {
* the concrete Service URL-ending, where the WebService is configured according to your WSDL´s Service Name
* (e.g. &quot;/Weather&quot; when there is this inside your WSDL: &lt;wsdl:service name=&quot;Weather&quot;&gt;)
*/
public String getBaseAndServiceEndingUrl() {
return baseUrl + serviceUrlEnding;
public String baseAndServiceEndingUrl() {
return baseUrl() + serviceUrlEnding();
}

// Register Filter for Correlating Logmessages from the same Service-Consumer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import de.codecentric.cxf.TestConfiguration;
import de.codecentric.cxf.common.BootStarterCxfException;
import de.codecentric.cxf.configuration.CxfAutoConfiguration;
import de.codecentric.cxf.soaprawclient.SoapRawClient;
Expand Down Expand Up @@ -35,7 +34,7 @@ public SoapRawClient soapRawClient() throws BootStarterCxfException {

private String buildUrl() {
// return something like http://localhost:8084/soap-api/WeatherSoapService
return "http://localhost:8087" + cxfAutoConfiguration.getBaseAndServiceEndingUrl();
return "http://localhost:8087" + cxfAutoConfiguration.baseAndServiceEndingUrl();
}

@Autowired
Expand Down

0 comments on commit 13e7b72

Please sign in to comment.