List all exposed/available endpoints of RestEasy service?

前端 未结 5 2156
甜味超标
甜味超标 2021-02-12 15:51

Is it possible to list all exposed/available endpoints of RestEasy service in a simple way?

5条回答
  •  醉梦人生
    2021-02-12 16:28

    Even it is an old post, I give my answer here.

    Here is the implementation from RestEasy shipped with JBoss. You can use it, or you can write your own. The implementation returns an object with an array property where you can find a uriTemplate String for each RestEasy Resource.

    You need to iterate over all entries and get the info you need:

    RegistryData.entries.get(index).uriTemplate

    The implementation of org.jboss.resteasy.plugins.stats.RegistryStatsResource.get method:

    public RegistryData get() throws JAXBException {
        ResourceMethodRegistry registry = (ResourceMethodRegistry)ResteasyProviderFactory.getContextData(Registry.class);
        RegistryData data = new RegistryData();
        Iterator i$ = registry.getRoot().getBounded().keySet().iterator();
    
        label85:
        while(i$.hasNext()) {
            String key = (String)i$.next();
            List invokers = (List)registry.getRoot().getBounded().get(key);
            RegistryEntry entry = new RegistryEntry();
            data.getEntries().add(entry);
            entry.setUriTemplate(key);
            Iterator i$ = invokers.iterator();
    
            while(true) {
                while(true) {
                    if (!i$.hasNext()) {
                        continue label85;
                    }
    
                    ResourceInvoker invoker = (ResourceInvoker)i$.next();
                    if (invoker instanceof ResourceMethod) {
                        ResourceMethod rm = (ResourceMethod)invoker;
    
                        Object method;
                        for(Iterator i$ = rm.getHttpMethods().iterator(); i$.hasNext(); entry.getMethods().add(method)) {
                            String httpMethod = (String)i$.next();
                            method = null;
                            if (httpMethod.equals("GET")) {
                                method = new GetResourceMethod();
                            } else if (httpMethod.equals("PUT")) {
                                method = new PutResourceMethod();
                            } else if (httpMethod.equals("DELETE")) {
                                method = new DeleteResourceMethod();
                            } else if (httpMethod.equals("POST")) {
                                method = new PostResourceMethod();
                            } else if (httpMethod.equals("OPTIONS")) {
                                method = new OptionsResourceMethod();
                            } else if (httpMethod.equals("TRACE")) {
                                method = new TraceResourceMethod();
                            } else if (httpMethod.equals("HEAD")) {
                                method = new HeadResourceMethod();
                            }
    
                            ((ResourceMethodEntry)method).setClazz(rm.getResourceClass().getName());
                            ((ResourceMethodEntry)method).setMethod(rm.getMethod().getName());
                            AtomicLong stat = (AtomicLong)rm.getStats().get(httpMethod);
                            if (stat != null) {
                                ((ResourceMethodEntry)method).setInvocations(stat.longValue());
                            } else {
                                ((ResourceMethodEntry)method).setInvocations(0L);
                            }
    
                            MediaType[] arr$;
                            int len$;
                            int i$;
                            MediaType mediaType;
                            if (rm.getProduces() != null) {
                                arr$ = rm.getProduces();
                                len$ = arr$.length;
    
                                for(i$ = 0; i$ < len$; ++i$) {
                                    mediaType = arr$[i$];
                                    ((ResourceMethodEntry)method).getProduces().add(mediaType.toString());
                                }
                            }
    
                            if (rm.getConsumes() != null) {
                                arr$ = rm.getConsumes();
                                len$ = arr$.length;
    
                                for(i$ = 0; i$ < len$; ++i$) {
                                    mediaType = arr$[i$];
                                    ((ResourceMethodEntry)method).getConsumes().add(mediaType.toString());
                                }
                            }
                        }
                    } else {
                        ResourceLocator rl = (ResourceLocator)invoker;
                        SubresourceLocator locator = new SubresourceLocator();
                        locator.setClazz(rl.getMethod().getDeclaringClass().getName());
                        locator.setMethod(rl.getMethod().getName());
                        entry.setLocator(locator);
                    }
                }
            }
        }
    
        return data;
    }
    

    See also: WildFly management - list/detect REST endpoints deployed in WildFly

提交回复
热议问题