How to extract header values from Request

0
Hi all I am struggeling  to find any information on how to get header values from the current user Request.  This is required because my current project is behind an ALB that injects some header values.  These values are needed for some custom Auth code. 
asked
3 answers
1

 

    @java.lang.Override
    public java.lang.String executeAction() throws Exception
    {
        // BEGIN USER CODE
        Optional<IMxRuntimeRequest> optionalMXRequest = getContext().getRuntimeRequest();
        if(optionalMXRequest.isEmpty()) {
            LOG.error("Context has empty IMXRuntimeRequest");
            throw new Exception("No IMxRuntimeRequest found");
        }
        LOG.debug("Context has IMXRuntimeRequest");
        IMxRuntimeRequest request = optionalMXRequest.get();
        LOG.debug("request headers start");
        Enumeration<String> headerNames = request.getHttpServletRequest().getHeaderNames();
        String value = "";
        while(headerNames.hasMoreElements()) {
            if(this.Key==((String) headerNames.nextElement())) {
                value = request.getHeader(this.Key);
                LOG.debug(this.Key+":"+value);
            }
        }
        if(value=="") {
            LOG.error("Header with Key:"+this.Key+" Does not exist");
            throw new Exception("Header not found");
        }
        LOG.debug("request headers end");
        return value;
        // END USER CODE
    }    

 

answered
0

Hi Alwyn,

Make sure you have an httpRequest parameter in your webservice microflow, then you can just do a retrieve by association from $httpRequest/HttpHeaders

answered
0

Hi ,

 

Have you tried using JamCommons ?  it has a javaaction to get header value   https://marketplace.mendix.com/link/component/71280  

 

Hope this helps.

 

Thanks

answered