WebserviceContext - 7.3

Talend ESB Service Developer Guide

Version
7.3
Language
English
Product
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Module
Talend ESB
Talend Runtime
Content
Design and Development
Installation and Upgrade
Last publication date
2023-04-17

The WebserviceContext interface is part of the JAX-WS specification. It allows you to access several context informations the runtime has associated to your service call.

The following code fragment show how to use some parts of the WebserviceContext.

public class CustomerServiceImpl implements CustomerService {
   @Resource
   WebServiceContext wsContext;

   public List<Customer> getCustomersByName(String name) 
      throws NoSuchCustomerException {
      Principal pr = wsContext.getUserPrincipal();

      // Only joe may access this service operation
      if (pr == null || !"joe".equals(pr.getName())) {
         throw new RuntimeException("Access denied");
      }

      // Only the sales role may access this operation
      if (!wsContext.isUserInRole("sales")) {
         throw new RuntimeException("Access denied");
      }

      MessageContext mContext = wsContext.getMessageContext();

      // See which contents the message context has
      Set<String> s = mContext.keySet();

      // Using this cxf specific code you can access 
      // the CXF Message and Exchange objects
      WrappedMessageContext wmc = (WrappedMessageContext)mContext;
      Message m = wmc.getWrappedMessage();
      Exchange ex = m.getExchange();
   }
}