Custom REST filters

更新时间:
复制 MD 格式

SOFAStack provides the JAXRSProviderManager class for REST, which you can use to create custom filters.

The JAXRSProviderManager class runs on the server-side and takes effect at service startup. The interface is as follows:

com.alipay.sofa.rpc.server.rest.RestServer#registerProvider

After initialization, call the following method to register your custom filter.

com.alipay.sofa.rpc.config.JAXRSProviderManager#registerCustomProviderInstance

A custom filter must follow REST specifications and implement one of the following interfaces:

javax.ws.rs.container.ContainerResponseFilter
or
javax.ws.rs.container.ContainerRequestFilter

After the REST server starts, you must first register and then start the service for bare SOFARPC. The process is similar when using a SOFABoot environment. For a specific implementation, see the following example:

com.alipay.sofa.rpc.server.rest.TraceRequestFilter
com.alipay.sofa.rpc.server.rest.TraceResponseFilter