我在客户端应用程序上下文xml中添加了以下配置:
<bean id="customTimeoutConfigInterceptor" class="com.hs18.inventory.client.interceptor.CustomTimeoutConfigInterceptor" />
<jaxrs:client id="inventoryServiceEndPoint"
address="http://$INVENTORY_CLIENT{inventory.api.host}:$INVENTORY_CLIENT{inventory.api.port}/api/1"
serviceClass="com.inventory.common.InventoryService"
inheritHeaders="true">
<jaxrs:providers>
<ref bean="hs18ResponseExceptionMapper" />
</jaxrs:providers>
<jaxrs:inFaultInterceptors>
<ref bean="customTimeoutConfigInterceptor" />
</jaxrs:inFaultInterceptors>
</jaxrs:client>
当客户端超时我想将请求放入消息队列时,我通过CustomTimeoutConfigInterceptor类尝试这个。但是从不调用handleMessage
方法。以下是代码。
public class CustomTimeoutConfigInterceptor extends AbstractPhaseInterceptor<Message> {
@Resource
InventoryServiceAsync inventoryServiceAsync;
public CustomTimeoutConfigInterceptor() {
super(Phase.PREPARE_SEND_ENDING);
}
@Override
public void handleMessage(Message message) throws Fault {
Exception exception = message.getContent(Exception.class);
if(exception.getMessage().equals("Connection Refused")){
if(message.getContent(List.class) != null && !message.getContent(List.class).isEmpty()){
Object request = message.getContent(List.class).get(0);
if(request.getClass().getAnnotation(Command.class) != null){
inventoryServiceAsync.sendCommand((ICommand)request);
}
}
}
}
}
答案 0 :(得分:0)
这是否适用于JAX-RS客户端到达某个外部端点?如果是这样,我可以说几件事:
连接超时或客户端超时发生在&#34; out&#34;通信堆栈的一部分,因此您可能希望在outFaultInterceptors
而不是
从上一点开始,您的拦截器构造函数上设置的阶段也需要更新,我已尝试将其设置为Phase.POST_STREAM
并且似乎正在运行。