@Override public List<AbstractModelComponent> getComponents() { List<AbstractModelComponent> components = new LinkedList<AbstractModelComponent>(); components.addAll(getConstructors()); components.addAll(getFields()); components.addAll(getSetterMethods()); components.addAll(getResourceMethods()); components.addAll(getSubResourceMethods()); components.addAll(getSubResourceLocators()); return components; } }
@Override public String toString() { return "AbstractResource(" + ((null == getPath()) ? "" : ("\"" + getPath().getValue() + "\", - ")) + getResourceClass().getSimpleName() + ": " + getConstructors().size() + " constructors, " + getFields().size() + " fields, " + getSetterMethods().size() + " setter methods, " + getResourceMethods().size() + " res methods, " + getSubResourceMethods().size() + " subres methods, " + getSubResourceLocators().size() + " subres locators " + ")"; }
private Resource generateSubResource(AbstractResource r, String path) { Resource wadlResource = new Resource(); if (r.isRootResource()) { StringBuilder b = new StringBuilder(r.getPath().getValue()); if (!(r.getPath().getValue().endsWith("/") || path.startsWith("/"))) { b.append("/"); } b.append(path); wadlResource.setPath(b.toString()); } // for each sub-resource method Map<String, Param> wadlSubResourceParams = new HashMap<String, Param>(); for (AbstractSubResourceMethod m : r.getSubResourceMethods()) { // find or create sub resource for uri template String template = m.getPath().getValue(); if (!template.equals(path) && !template.equals('/' + path)) { continue; } com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlSubResourceParams, m); wadlResource.getMethodOrResource().add(wadlMethod); } // add parameters that are associated with each sub-resource method PATH template for (Param wadlParam : wadlSubResourceParams.values()) { wadlResource.getParam().add(wadlParam); } return wadlResource; }
Map<String, Map<String, Param>> wadlSubResourcesParams = new HashMap<String, Map<String, Param>>(); for (AbstractSubResourceMethod m : r.getSubResourceMethods()) {
new HashMap<PathPattern, ResourceMethodMap>(); for (final AbstractSubResourceMethod method : resource.getSubResourceMethods()) {
abstractSubResourceMethod, m, isEncoded); resource.getSubResourceMethods().add(abstractSubResourceMethod);
@Override public List<AbstractModelComponent> getComponents() { List<AbstractModelComponent> components = new LinkedList<AbstractModelComponent>(); components.addAll(getConstructors()); components.addAll(getFields()); components.addAll(getSetterMethods()); components.addAll(getResourceMethods()); components.addAll(getSubResourceMethods()); components.addAll(getSubResourceLocators()); return components; } }
@Override public List<AbstractModelComponent> getComponents() { List<AbstractModelComponent> components = new LinkedList<AbstractModelComponent>(); components.addAll(getConstructors()); components.addAll(getFields()); components.addAll(getSetterMethods()); components.addAll(getResourceMethods()); components.addAll(getSubResourceMethods()); components.addAll(getSubResourceLocators()); return components; } }
@Override public String toString() { return "AbstractResource(" + ((null == getPath()) ? "" : ("\"" + getPath().getValue() + "\", - ")) + getResourceClass().getSimpleName() + ": " + getConstructors().size() + " constructors, " + getFields().size() + " fields, " + getSetterMethods().size() + " setter methods, " + getResourceMethods().size() + " res methods, " + getSubResourceMethods().size() + " subres methods, " + getSubResourceLocators().size() + " subres locators " + ")"; }
@Override public String toString() { return "AbstractResource(" + ((null == getPath()) ? "" : ("\"" + getPath().getValue() + "\", - ")) + getResourceClass().getSimpleName() + ": " + getConstructors().size() + " constructors, " + getFields().size() + " fields, " + getSetterMethods().size() + " setter methods, " + getResourceMethods().size() + " res methods, " + getSubResourceMethods().size() + " subres methods, " + getSubResourceLocators().size() + " subres locators " + ")"; }
@GET @Path(PATH_RESOURCE) @Produces(MediaType.APPLICATION_JSON) public Response listAllResourcesRoutes(@Context Application application, @Context HttpServletRequest request){ String basePath = request.getRequestURL().toString(); basePath = basePath.substring(0,basePath.length() - PATH_META.length() - PATH_RESOURCE.length() -1); ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(RESOURCE_BASE,basePath); ArrayNode resources = JsonNodeFactory.instance.arrayNode(); root.put( RESOURCE_RESOURCES, resources ); for ( Class<?> aClass : application.getClasses()){ if ( isAnnotatedResourceClass(aClass)){ AbstractResource resource = IntrospectionModeller.createResource(aClass); ObjectNode resourceNode = JsonNodeFactory.instance.objectNode(); String uriPrefix = resource.getPath().getValue(); for ( AbstractSubResourceMethod srm : resource.getSubResourceMethods() ) { String uri = uriPrefix + "/" + srm.getPath().getValue(); addTo( resourceNode, uri, srm, joinUri(basePath, uri) ); } for ( AbstractResourceMethod srm : resource.getResourceMethods() ) { addTo( resourceNode, uriPrefix, srm, joinUri( basePath, uriPrefix ) ); } resources.add( resourceNode ); } } return Response.ok().entity( root ).build(); }
protected Set<Class> getDefiningClasses(AbstractResource resourceClass) { HashSet<Class> definingClasses = new HashSet<Class>(); for (AbstractResourceMethod resourceMethod : resourceClass.getResourceMethods()) { definingClasses.add(new AnnotatedMethod(resourceMethod.getMethod()).getMethod().getDeclaringClass()); } for (AbstractResourceMethod resourceMethod : resourceClass.getSubResourceMethods()) { definingClasses.add(new AnnotatedMethod(resourceMethod.getMethod()).getMethod().getDeclaringClass()); } for (AbstractSubResourceLocator locator : resourceClass.getSubResourceLocators()) { definingClasses.add(new AnnotatedMethod(locator.getMethod()).getMethod().getDeclaringClass()); } return definingClasses; }
import com.sun.jersey.api.model.AbstractResource; import com.sun.jersey.api.model.AbstractSubResourceMethod; import com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; public class AnimalsTest { public static void main(String [] args) { AbstractResource resource = IntrospectionModeller.createResource(AnimalResource.class); System.out.println("Path is " + resource.getPath().getValue()); String uriPrefix = resource.getPath().getValue(); for (AbstractSubResourceMethod srm :resource.getSubResourceMethods()) { String uri = uriPrefix + "/" + srm.getPath().getValue(); System.out.println(srm.getHttpMethod() + " at the path " + uri + " return " + srm.getReturnType().getName()); } } }
private Resource generateSubResource(AbstractResource r, String path) { Resource wadlResource = new Resource(); if (r.isRootResource()) { StringBuilder b = new StringBuilder(r.getPath().getValue()); if (!(r.getPath().getValue().endsWith("/") || path.startsWith("/"))) { b.append("/"); } b.append(path); wadlResource.setPath(b.toString()); } // for each sub-resource method Map<String, Param> wadlSubResourceParams = new HashMap<String, Param>(); for (AbstractSubResourceMethod m : r.getSubResourceMethods()) { // find or create sub resource for uri template String template = m.getPath().getValue(); if (!template.equals(path) && !template.equals('/' + path)) { continue; } com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlSubResourceParams, m); wadlResource.getMethodOrResource().add(wadlMethod); } // add parameters that are associated with each sub-resource method PATH template for (Param wadlParam : wadlSubResourceParams.values()) { wadlResource.getParam().add(wadlParam); } return wadlResource; }
private Resource generateSubResource(AbstractResource r, String path) { Resource wadlResource = new Resource(); if (r.isRootResource()) { StringBuilder b = new StringBuilder(r.getPath().getValue()); if (!(r.getPath().getValue().endsWith("/") || path.startsWith("/"))) { b.append("/"); } b.append(path); wadlResource.setPath(b.toString()); } // for each sub-resource method Map<String, Param> wadlSubResourceParams = new HashMap<String, Param>(); for (AbstractSubResourceMethod m : r.getSubResourceMethods()) { // find or create sub resource for uri template String template = m.getPath().getValue(); if (!template.equals(path) && !template.equals('/' + path)) { continue; } com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlSubResourceParams, m); wadlResource.getMethodOrResource().add(wadlMethod); } // add parameters that are associated with each sub-resource method PATH template for (Param wadlParam : wadlSubResourceParams.values()) { wadlResource.getParam().add(wadlParam); } return wadlResource; }
@GET @Path(PATH_RESOURCE) @Produces(MediaType.APPLICATION_JSON) public Response listAllResourcesRoutes(@Context Application application, @Context HttpServletRequest request){ String basePath = request.getRequestURL().toString(); basePath = basePath.substring(0,basePath.length() - PATH_META.length() - PATH_RESOURCE.length() -1); ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put("base",basePath); ArrayNode resources = JsonNodeFactory.instance.arrayNode(); root.put( "resources", resources ); for ( Class<?> aClass : application.getClasses()){ if ( isAnnotatedResourceClass(aClass)){ AbstractResource resource = IntrospectionModeller.createResource(aClass); ObjectNode resourceNode = JsonNodeFactory.instance.objectNode(); String uriPrefix = resource.getPath().getValue(); for ( AbstractSubResourceMethod srm : resource.getSubResourceMethods() ) { String uri = uriPrefix + "/" + srm.getPath().getValue(); addTo( resourceNode, uri, srm, joinUri(basePath, uri) ); } for ( AbstractResourceMethod srm : resource.getResourceMethods() ) { addTo( resourceNode, uriPrefix, srm, joinUri( basePath, uriPrefix ) ); } resources.add( resourceNode ); } } return Response.ok().entity( root ).build(); }
for (AbstractSubResourceMethod srm :resource.getSubResourceMethods()) for (AbstractSubResourceMethod superSrm : superResource.getSubResourceMethods())
new HashMap<PathPattern, ResourceMethodMap>(); for (final AbstractSubResourceMethod method : resource.getSubResourceMethods()) {
new HashMap<PathPattern, ResourceMethodMap>(); for (final AbstractSubResourceMethod method : resource.getSubResourceMethods()) {
abstractSubResourceMethod, m, isEncoded); resource.getSubResourceMethods().add(abstractSubResourceMethod);