Skip to content

Commit

Permalink
do not invoke Bean methods in PostConstruct to prevent circular refer…
Browse files Browse the repository at this point in the history
  • Loading branch information
erikpetzold authored and jonashackt committed Nov 22, 2022
1 parent 5bb12b3 commit 1ae93a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,14 @@ public class CxfAutoConfiguration {
@Value("${cxf.servicelist.title:CXF SpringBoot Starter - service list}")
private String serviceListTitle;

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


@Bean
public WebServiceAutoDetector webServiceAutoDetector(ApplicationContext applicationContext) throws BootStarterCxfException {
return new WebServiceAutoDetector(new WebServiceScanner(), applicationContext);
}

@PostConstruct
public void setUp() throws BootStarterCxfException {
webServiceClient = webServiceAutoDetector(null).searchAndInstantiateWebServiceClient();
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
Expand Down Expand Up @@ -126,7 +118,7 @@ public Endpoint endpoint() throws BootStarterCxfException {
endpoint.setServiceName(webServiceClient().getServiceName());
endpoint.setWsdlLocation(webServiceClient().getWSDLDocumentLocation().toString());
if (publishedEndpointUrl.equals("NOT_SET")) {
endpoint.setPublishedEndpointUrl(webServiceClient.getServiceName().getLocalPart());
endpoint.setPublishedEndpointUrl(webServiceClient().getServiceName().getLocalPart());
} else {
endpoint.setPublishedEndpointUrl(publishedEndpointUrl);
}
Expand All @@ -138,7 +130,7 @@ public Endpoint endpoint() throws BootStarterCxfException {
@Bean
public Service webServiceClient() throws BootStarterCxfException {
// Needed for correct ServiceName & WSDLLocation to publish contract first incl. original WSDL
return webServiceClient;
return webServiceAutoDetector(null).searchAndInstantiateWebServiceClient();
}

/**
Expand All @@ -152,7 +144,10 @@ public String baseUrl() {
* @return the concrete Service URL-ending, where the WebService is configured according to your WSDL´s Service Name
* (e.g. "/Weather" when there is this inside your WSDL: <wsdl:service name="Weather">)
*/
public String serviceUrlEnding() {
public String serviceUrlEnding() throws BootStarterCxfException {
if (serviceUrlEnding == null) {
serviceUrlEnding = "/" + webServiceClient().getServiceName().getLocalPart();
}
return serviceUrlEnding;
}

Expand All @@ -161,7 +156,7 @@ public String serviceUrlEnding() {
* the concrete Service URL-ending, where the WebService is configured according to your WSDL´s Service Name
* (e.g. "/Weather" when there is this inside your WSDL: <wsdl:service name="Weather">)
*/
public String baseAndServiceEndingUrl() {
public String baseAndServiceEndingUrl() throws BootStarterCxfException {
return baseUrl() + serviceUrlEnding();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ public class XmlValidationConfiguration {

@Autowired
public Endpoint endpoint;

@PostConstruct
public void configureInterceptor2Endpoint() {
EndpointImpl endpointImpl = (EndpointImpl)endpoint; // we need the implementation here, to configure our Interceptor
endpointImpl.getOutFaultInterceptors().add(soapInterceptor());
}


@Bean
public SoapFaultBuilder soapFaultBuilder() {
return new SoapFaultBuilder();
Expand All @@ -46,6 +40,8 @@ public SoapFaultBuilder soapFaultBuilder() {
public AbstractSoapInterceptor soapInterceptor() {
XmlValidationInterceptor xmlValidationInterceptor = new XmlValidationInterceptor();
xmlValidationInterceptor.setSoapFaultBuilder(soapFaultBuilder());
EndpointImpl endpointImpl = (EndpointImpl)endpoint; // we need the implementation here, to configure our Interceptor
endpointImpl.getOutFaultInterceptors().add(xmlValidationInterceptor);
return xmlValidationInterceptor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TestServiceSystemTestConfiguration {
* CXF JaxWs Client
*/
@Bean
public WeatherService weatherServiceClient() {
public WeatherService weatherServiceClient() throws BootStarterCxfException {
JaxWsProxyFactoryBean jaxWsFactory = new JaxWsProxyFactoryBean();
jaxWsFactory.setServiceClass(WeatherService.class);
jaxWsFactory.setAddress(buildUrl());
Expand All @@ -31,7 +31,7 @@ public SoapRawClient soapRawClient() throws BootStarterCxfException {
return new SoapRawClient(buildUrl(), WeatherService.class);
}

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

0 comments on commit 1ae93a4

Please sign in to comment.