Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 649

Java Spring fetch Headers while scanning classes

$
0
0
@ResponseBody    @GetMapping("/all/{hotelId}")    public List<RoomEntity> allRoomsByHotel(@PathVariable Long hotelId, @RequestHeader(value = "hotelId", required = true) long hotelId2){        System.out.println("Value of header 'hotelId': " + hotelId2);        System.out.println("Path variable 'hotelId': " + hotelId);        List<RoomEntity> allRooms = roomService.allRoomsByHotel(hotelId);        return allRooms;    }

So i do have this endpoint with requested header hotelIdand im writing other class that will scan through all classes in project to gather informations about these endpoints including required headers

but when i try something like this

public Set<Class<?>> findAllClassesUsingReflectionsLibrary(String packageName) {        Reflections reflections = new Reflections(packageName, new SubTypesScanner(false));        return reflections.getSubTypesOf(Object.class);    }    public Map<Class<?>, Set<EndpointInfo>> findEndpointsInClasses(Set<Class<?>> classes) {        Map<Class<?>, Set<EndpointInfo>> classEndpointsMap = new HashMap<>();        for (Class<?> clazz : classes) {            Set<EndpointInfo> endpoints = new HashSet<>();            Method[] methods = clazz.getMethods();            for (Method method : methods) {                if (method.isAnnotationPresent(RequestHeader.class)){                    System.out.println("here!");                    RequestHeader requestHeader = method.getAnnotation(RequestHeader.class);                    System.out.println(requestHeader);                }

its not fetching info, is there any other way to make it work?

I've tried debugging it, but cant find anything about headers in this class.My other approach

if (method.isAnnotationPresent(GetMapping.class)) {                    GetMapping getMapping = method.getAnnotation(GetMapping.class);                    System.out.println(Arrays.toString(getMapping.headers()));}

but it just cant fetch it.


Viewing all articles
Browse latest Browse all 649

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>