Last active
November 1, 2019 12:41
-
-
Save thomashartm/e9324b3a25fab3305eaf1486a8cbeb0b to your computer and use it in GitHub Desktop.
Prints out a list of servlets which are registered as OSGi components. The purpose is to find servlets which are listening to fixed paths or the default resource type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.osgi.service.cm.Configuration | |
import org.osgi.service.component.runtime.ServiceComponentRuntime | |
def scr = getService(ServiceComponentRuntime.class) | |
def descs = scr.getComponentDescriptionDTOs() | |
def i = 0 | |
def onlyDefault = false | |
def jsonSlurper = new JsonSlurper() | |
jsonSlurper.setChop(false) | |
descs.each{dsc-> | |
String[] interfaces = dsc.serviceInterfaces | |
if(interfaces.contains("javax.servlet.Servlet") ){ | |
def json = jsonSlurper.parseText(dsc.toString()) | |
if(onlyDefault && !json.properties.toString().contains("sling/servlet/default")){ | |
return | |
} | |
println json.name + " " | |
println json.properties['sling.servlet.paths'] | |
println json.properties['sling.servlet.resourceTypes'] | |
println json.properties['sling.servlet.extensions'] | |
println json.properties['sling.servlet.methods'] | |
println json.properties['sling.servlet.selectors'] | |
println "-----------" | |
i++ | |
} | |
} | |
println "servlets: " + i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment