e1d5302e19e1fd883bded6c24ac2950c9c51d16d
[SpringWebServicesForFun/.git] /
1 package de.spring.webservices.endpoints;
2
3 import javax.servlet.http.HttpServletRequest;
4
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7 import org.springframework.util.StringUtils;
8 import org.springframework.ws.context.MessageContext;
9 import org.springframework.ws.server.EndpointInterceptor;
10 import org.springframework.ws.transport.context.TransportContext;
11 import org.springframework.ws.transport.context.TransportContextHolder;
12 import org.springframework.ws.transport.http.HttpServletConnection;
13
14 public class CustomHeaderInterceptor implements EndpointInterceptor {
15         private static final Logger LOGGER = LoggerFactory.getLogger(CustomHeaderInterceptor.class);
16         private static final String MY_CUSTOM_HEADER = "MY_CUSTOM_HEADER";
17
18         @Override
19         public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
20                 TransportContext transport = TransportContextHolder.getTransportContext();
21         
22                 if (transport != null) {
23                         HttpServletConnection connection = (HttpServletConnection) transport.getConnection();
24                         HttpServletRequest headers = connection.getHttpServletRequest();
25                         String headerValue = headers.getHeader(MY_CUSTOM_HEADER);
26                         
27                         if (!StringUtils.isEmpty(headerValue)) {
28                                 LOGGER.info("Custom header value: " + headerValue);
29                         }
30                 }
31                 
32                 return true;
33         }
34
35         @Override
36         public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
37                 return true;
38         }
39
40         @Override
41         public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
42                 return true;
43         }
44
45         @Override
46         public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) throws Exception {
47                 
48         }
49
50 }