我在客户端应用程序上下文 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);
}
}
}
}
}