Guest User

IpfEndpointWithParamsInterceptor

a guest
May 9th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. /**
  2.  * Interceptor to modify the endpoint address based on the originalUrl header.
  3.  * Used to support IPF endpoints containing pre-existing parameters in their URL.
  4.  */
  5. @Slf4j
  6. public class IpfEndpointWithParamsInterceptor extends AbstractPhaseInterceptor<Message> {
  7.  
  8.   public IpfEndpointWithParamsInterceptor() {
  9.     super(Phase.PRE_LOGICAL);
  10.   }
  11.  
  12.   @Override
  13.   public void handleMessage(Message message) throws Fault {
  14.     String address = (String) message.get(Message.ENDPOINT_ADDRESS);
  15.     Object headers = message.get("org.apache.cxf.headers.Header.list");
  16.  
  17.     if (headers instanceof List<?> headerList && address != null) {
  18.       for (int i = 0; i < headerList.size(); i++) {
  19.         Object obj = headerList.get(i);
  20.         if (obj instanceof SoapHeader header && header.getName().getLocalPart().equals("originalUrl")
  21.             && header.getName().getNamespaceURI().equals("http://example.com/schema")) {
  22.  
  23.           Object headerObj = header.getObject();
  24.           if (headerObj != null) {
  25.             String originalUrl = headerObj.toString();
  26.             LOGGER.debug("Found originalUrl: {}", originalUrl);
  27.             LOGGER.debug("Endpoint address after Camel chewed on it: {}", address);
  28.  
  29.             message.put(Message.ENDPOINT_ADDRESS, originalUrl);
  30.             headerList.remove(i);
  31.             LOGGER.debug("Modified endpoint address to: {} and removed the soap header", originalUrl);
  32.             break;
  33.           }
  34.         }
  35.       }
  36.     }
  37.   }
Advertisement
Add Comment
Please, Sign In to add comment