-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddClientMessagesInterceptor.java
37 lines (30 loc) · 1.11 KB
/
AddClientMessagesInterceptor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.iorga.ivif.ja;
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.interception.PostProcessInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.util.List;
@Provider
@ServerInterceptor
public class AddClientMessagesInterceptor implements PostProcessInterceptor {
private static final Logger LOG = LoggerFactory.getLogger(AddClientMessagesInterceptor.class);
@Inject
private ClientMessages clientMessages;
@Inject
private HeaderUtil headerUtil;
@Override
public void postProcess(ServerResponse response) {
final List<Message> messages = clientMessages.getMessages();
if (!messages.isEmpty()) {
try {
headerUtil.writeTo(messages, MessageUtils.MESSAGES_HEADER_SUFFIX, response);
} catch (IOException e) {
LOG.error("Error while adding client messages to the response", e);
}
}
}
}