简体   繁体   English

CXF生成的Web服务的切入点是什么?

[英]What is the entry point in a CXF generated web service?

Using a contract-first approach, I generated a web service from a WSDL, using CXF. 使用合同优先的方法,我使用CXF从WSDL生成了Web服务。

The web service loads fine by Tomcat 7 and responds properly to SOAP messages. Tomcat 7可以很好地加载Web服务,并可以正确响应SOAP消息。

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). 但是,尽管我从WSDL和XSD了解了自动生成的Java类,但是我不确定我知道入口点在哪里(例如,可以启用验证 )。

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. 由于熟悉的main()方法只是默认的入口点,而不是强制性的 ,因此我假设CXF为此使用不同的入口点。

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): 当我构建Web服务(使用包含CXF插件的pom.xml)时,仅生成2个软件包(足以建立有效的 Web服务):

  1. One for the WSDL itself, containing only 3 Java modules: ObjectFactory.java, MyBinding.java, MyService.java 一个用于WSDL本身,仅包含3个Java模块: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. 第二个用于XSD模式,其中包含模式中定义的每个类型的Java类。

I am suspecting that MyService.java, which extends a class named Service is where I should be looking for that entry point. 我怀疑MyService.java(它扩展了一个名为Service的类)是我应该在其中寻找该入口点的地方。 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: 顺便说一句,我试图从Tomcat控制台中解决这个问题,但这就是启动时所有Web服务的日志:

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. CXF似乎很好地隐藏了实现细节,但是我想知道在哪里挂接我的初始化定制。

CXFServlet is generally the entry point for your service. CXFServlet通常是服务的入口点。 Tomcat routes the HTTP request to your webapp, and the servlet-mapping defines the Servlet that receives the request. Tomcat将HTTP请求路由到您的Web应用程序,并且Servlet映射定义了接收请求的Servlet。 If you want to intercept the request before it reaches CXF, you could write a Servlet Filter . 如果要在请求到达CXF之前对其进行拦截,则可以编写Servlet Filter

For simple validation needs, CXF does support schema validation via configuration . 对于简单的验证需求,CXF确实支持通过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. 如果您想在消息到达您的服务之前对其做一些更奇妙的事情,并从CXF的功能中受益,我建议您熟悉CXF拦截器。 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 . CXF文档详细介绍了编写拦截器的阶段和说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM