Question

Using a contract-first approach, I generated a web service from a WSDL, using CXF.

The web service loads fine by Tomcat 7 and responds properly to SOAP messages.

But while I understand the auto-generated Java classes from the WSDL and XSD, I am not sure I know where the entry point is (so that I can enable validation, for example).

Since the familiar main() method is only a default entry point and is not mandatory, I am assuming that CXF uses a different entry point for that purpose.

When I build the web service (using a pom.xml that contains the CXF plugin), only 2 packages are generated (sufficient for establishing a working web service):

  1. One for the WSDL itself, containing only 3 Java modules: ObjectFactory.java, MyBinding.java, MyService.java
  2. The second is for the XSD schema, containing a Java class for each and every type defined in the schema.

I am suspecting that MyService.java, which extends a class named Service is where I should be looking for that entry point. But how does it do "the magic"?

BTW, I tried figuring this out from the Tomcat console, but that's all the web service logs upon startup:

Oct 4, 2013 11:27:47 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started

Oct 4, 2013 11:27:47 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Fri Oct 04 11:27:47 EDT 2013]; root of context hierarchy

Oct 4, 2013 11:27:47 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]

Oct 4, 2013 11:27:47 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]

Oct 4, 2013 11:27:47 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-soap.xml]

Oct 4, 2013 11:27:47 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]

Oct 4, 2013 11:27:47 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@17392df: defining beans [org.springframework.context.
annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.anno
tation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,cxf,org.apache.cxf.bus.spring.BusWiringBeanF
actoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.binding.soap.SoapBindin
gFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,myserviceWS,myserviceBinding]; root of factor
y hierarchy

Oct 4, 2013 11:27:47 AM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://myws.example.com/ns}MyService from WSDL: file:/C:/Users/Daniel/myws/src/main/wsdl/myws.wsdl

Oct 4, 2013 11:27:48 AM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be /myservice/soap

Oct 4, 2013 11:27:48 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1107 ms

CXF seems to be hiding the implementation details very well, but I would like to know where to hook my initialization customization.

Was it helpful?

Solution

CXFServlet is generally the entry point for your service. Tomcat routes the HTTP request to your webapp, and the servlet-mapping defines the Servlet that receives the request. If you want to intercept the request before it reaches CXF, you could write a Servlet Filter.

For simple validation needs, CXF does support schema validation via configuration.

If you want to do fancier things to a message before it reaches your service, and benefit from the functionality of CXF, I would recommend becoming familiar with CXF Interceptors. They are very powerful, and can intercept a message at any number of phases before it reaches the service, and after it exits the service. The CXF documentation has details on the phases and instructions on writing an Interceptor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top