I am struggling to get an JAXRS service up-and-running although it is for
its setup quasi identical to another JAXRS service I have running (on
another server).
My project is using libraries:
- Apache CXF-v3.5.2
- SPRING-v3.2.18 (legacy reasons)
- Jackson 2.13.1
The service was declared in an yaml file using openapi v3.0.3 from which
source and implementation classes where generated using the maven plugin
org.openapitools:openapi-generator-maven-plugin:6.2.0 with generator name
‘jaxrs-cxf’. The service endpoint is declared through xml as:
*<!-- JAXRS providers -->*
<bean id="jsonProvider" class=
"com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider">
<constructor-arg index="0">
<bean class=
"be.dvtm.aeo.common.data.jqdto.mapper.CustomObjectMapper"/>
</constructor-arg>
<constructor-arg index="1" value="#{
T(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider).BASIC_ANNOTATIONS }"
/>
</bean>
*<!-- CXF Swagger2Feature -->*
<bean id="SwaggerUiConfig" class=
"org.apache.cxf.jaxrs.swagger.ui.SwaggerUiConfig">
<property name="queryConfigEnabled" value="false"/>
<property name="url" value="services/swagger.yaml"/>
</bean>
<bean id="swagger2Feature" class=
"org.apache.cxf.jaxrs.swagger.Swagger2Feature">
<property name="basePath" value="/services"/>
<property name="supportSwaggerUi" value="true" />
<property name="swaggerUiConfig" ref="SwaggerUiConfig"/>
</bean>
*<!-- CXF Bean validation -->*
<bean id="exceptionMapper" class=
"be.dvtm.aeo.common.data.jqdto.mapper.CustomExceptionMapper" />
<bean id="validationProvider" class=
"org.apache.cxf.validation.BeanValidationProvider" />
<bean id="validationInInterceptor" class=
"org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor">
<property name="provider" ref="validationProvider" />
</bean>
<bean id="validationOutInterceptor" class=
"org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor">
<property name="provider" ref="validationProvider" />
</bean>
<bean id="JqDtoApi" class=
"be.dvtm.aeo.common.data.jqdto.api.impl.JqDtoApiServiceImpl">
<description>JQuery Datatable endpoint service
implementation</description>
</bean>
<bean id="cxf.wiremessage.logging" class=
"org.apache.cxf.ext.logging.LoggingFeature">
<property name="prettyLogging" value="false" />
</bean>
*<!-- JQDto REST API endpoint server -->*
<jaxrs:server id="jqdtoRestServer" basePackages=
"be.dvtm.aeo.common.data.jqdto" address="/">
<jaxrs:serviceBeans>
<ref bean="JqDtoApi" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider" />
<ref bean="exceptionMapper"/>
</jaxrs:providers>
<jaxrs:features>
<ref bean="swagger2Feature" />
<ref bean="cxf.wiremessage.logging" />
</jaxrs:features>
<jaxrs:inInterceptors>
<ref bean="validationInInterceptor" />
</jaxrs:inInterceptors>
*<!-- UJ: Do not use validation out interceptor as it
fails on Response types of the API *
* <jaxrs:outInterceptors>*
* <ref bean="validationOutInterceptor" />*
* </jaxrs:outInterceptors>*
* -->*
</jaxrs:server>
Basically the service interface class looks like:
@Path("/jqdto")
@Api(value = "/", description = "stripped")
@Consumes(MediaType.*APPLICATION_JSON*)
@Produces(MediaType.*APPLICATION_JSON*)
*public* *interface* JqDtoApi {
@POST
@Path("/getData")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "stripped", tags = { "JQDto" })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success",
response = JQDTOResponse.*class*),
@ApiResponse(code = 400, message = "Refused\\",
response = ErrorResponse.*class*),
@ApiResponse(code = 401, message = "Unauthorized")
})
Response *getData*(ContainerRequestContext requestContext,@Valid
@NotNull JQDTORequest jqDTORequest);
}
And the implementation class basically looks like (stripped):
@Service("JqDtoApi")
*public* *class* JqDtoApiServiceImpl *implements* JqDtoApi {
@Override
*public* Response *getData*(@Context ContainerRequestContext
requestCtx,JQDTORequest jqDTORequest) {
/* implementation */
}
}
This is all identical to the other JAXRS service I created previously.