All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.brutusin.demo.http.HttpAwareAction Maven / Gradle / Ivy

The newest version!
package org.brutusin.demo.http;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.brutusin.rpc.http.Cacheable;
import org.brutusin.rpc.http.HttpActionContext;
import org.brutusin.rpc.http.SafeAction;

public class HttpAwareAction extends SafeAction> {

    @Override
    public Cacheable> execute(Void input) throws Exception {
        Object request = HttpActionContext.getInstance().getRequest();
        if (!(request instanceof HttpServletRequest)) {
            throw new RuntimeException("Could not get the HttpServletRequest from the context");
        } else {
            HttpServletRequest httpReq = (HttpServletRequest) request;
            List ret = new ArrayList();
            Enumeration headerNames = httpReq.getHeaderNames();
            while (headerNames.hasMoreElements()) {
                String header = headerNames.nextElement();
                ret.add(header + ":" + httpReq.getHeader(header));
            }
            return Cacheable.never(ret);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy