alfa-laboratory / cxf-ws-client-spring-boot-starter

Best way to create JAX-WS PortType for your spring-boot application
https://alfa-laboratory.github.io/cxf-ws-client-spring-boot-starter/3.3.4/html5/index.html
Apache License 2.0
4 stars 2 forks source link
apache apache-cxf cxf factory-bean interceptor jax-ws porttype-stub soap spring spring-boot starter

Spring Boot Apache CXF WS-Clients starter

Codacy Badge Coverage Status Build Status Download

The best way to consumer your legacy jax-ws services.

Versions compatibility:

3.x.x – Spring Boot 2.x.x 1.x.x – Is too old, not supported

Quick start

Add as dependency

    dependencies {
        compile 'ru.alfalab.starter.cxf:starter:{starterVersion}'
    }

Enable or disable by spring.cxf.client.enabled bool option

How it works

  1. Cxf starter configure new CxfBeanDefinitionPostProcessor for making beans from each PortType stub with @WebService annotation
  2. Automatically scan classpath and find all classes with @WebService annotatoin. Configure BeanDefiniton for this stub and pass control to next stage for build bean instance.
  3. Each bean has constructed by factory bean - CxfWsStubBeanFactory. Factory bean match information about service endpoint by port type classname in spring.cxf configuration. See example below.
spring.cxf:
 clients:
  -
   endpoint: http://ws.srv/TESTSERVICE/TESTSERVICE12
   className: ru.testservice.TestService12PortType
  -
   endpoint: http://ws.srv/TEST/INFO/WSInfo12/WSInfo12PortType
   className: ru.test.info.WSInfo12PortType

By default all services searching in ru. package. If you need change it you have to add next properties into your application.yml. Also you can specify packages you don't want to scan. For example:

spring.cxf:
 packages:
  scan:
   - myorg.package
  skip:
   - myorg.package.skip

Interceptors

PortType stubs can be provided with a list of interceptors. If you want to use this feature, you have to declare your interceptor as Spring Bean in your code and annotate it with @CxfSpecificInterceptor or @CxfGlobalInterceptor. There are 4 types of interceptors: IN, IN_FAULT, OUT and OUT_FAULT.

For example:

@Bean
@CxfGlobalInterceptor(type = InterceptorType.OUT) (1)
my.awesome.in.Interceptor myAwesomeInInterceptor() {
    return new my.awesome.in.Interceptor();
}

or

@Bean
@CxfSpecificInterceptor(type = InterceptorType.IN, applyFor = { WSInfo12PortType.class, CorruptedWSInfo12PortType.class }) (2)
public WSS4JInInterceptor specificInterceptor() {
    return new WSS4JInInterceptor();
}
  1. Interceptor beans annotated with @CxfGlobalInterceptor will be applied to all found stubs.
  2. Interceptor beans annotated with @CxfSpecificInterceptor will be applied to stubs specified in applyFor annotation member.

Special thanks and authors