如何在Magnolia CMS(v 5.5.6)中为jax-rs端点提供自定义异常映射?

我创建了基于jax-rs的自定义端点。

@Path("/test")
public class MyEndpoint<D extends EndpointDefinition>  extends AbstractEndpoint<D> {

    @Path("/dosth")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public void doSth() {
        //some code here
    }
}

现在,我想为jax-rs端点添加自定义异常处理。我希望所有异常处理都放在一个地方,而不是每种方法都尝试捕获。试图添加jax-rs Exceptionmapper:

@Provider
public class CustomExceptionmapper implements Exceptionmapper<Throwable> {

   public Response toResponse(Throwable e) {
      return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
   }
}

不幸的是,木兰没有使用它。如何在Magnolia 5.5.6中注册此类映射器?

sky03191 回答:如何在Magnolia CMS(v 5.5.6)中为jax-rs端点提供自定义异常映射?

自定义异常映射器应在rest-integration JCR配置中注册。负责jax-rs提供程序的节点是

config.modules.rest-integration.config.additionalProviders

我已经通过我的自定义实现覆盖了默认异常映射器,现在它可以工作了。

enter image description here

本文链接:https://www.f2er.com/3067750.html

大家都在问