@Override public void visitAbstractResource(AbstractResource resource) { // uri template of the resource, if present should not contain null value if (resource.isRootResource() && ((null == resource.getPath()) || (null == resource.getPath().getValue()))) { issueList.add(new ResourceModelIssue( resource, ImplMessages.ERROR_RES_URI_PATH_INVALID(resource.getResourceClass(), resource.getPath()), true)); // TODO: is it really a fatal issue? } checkNonPublicMethods(resource); }
@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; }
@Override public Resource createResource( AbstractResource r, String path ) { Resource wadlResource = new Resource(); if (path != null) wadlResource.setPath(path); else if (r.isRootResource()) wadlResource.setPath(r.getPath().getValue()); return wadlResource; }
final ImmutableList.Builder<Class<?>> builder = ImmutableList.builder(); for (Object o : environment.jersey().getResourceConfig().getSingletons()) { if (o.getClass().isAnnotationPresent(Path.class)) { builder.add(o.getClass()); } } for (Class<?> klass : environment.jersey().getResourceConfig().getClasses()) { if (klass.isAnnotationPresent(Path.class)) { builder.add(klass); } } final List<String> endpoints = Lists.newArrayList(); for (Class<?> klass : builder.build()) { AbstractResource resource = IntrospectionModeller.createResource(klass); endpoints.add(resource.getPath().getValue()); }
@Override public void visitAbstractResource(AbstractResource resource) { // uri template of the resource, if present should not contain null value if (resource.isRootResource() && ((null == resource.getPath()) || (null == resource.getPath().getValue()))) { issueList.add(new ResourceModelIssue( resource, ImplMessages.ERROR_RES_URI_PATH_INVALID(resource.getResourceClass(), resource.getPath()), true)); // TODO: is it really a fatal issue? } checkNonPublicMethods(resource); }
@Override public void visitAbstractResource(AbstractResource resource) { // uri template of the resource, if present should not contain null value if (resource.isRootResource() && ((null == resource.getPath()) || (null == resource.getPath().getValue()))) { issueList.add(new ResourceModelIssue( resource, ImplMessages.ERROR_RES_URI_PATH_INVALID(resource.getResourceClass(), resource.getPath()), true)); // TODO: is it really a fatal issue? } checkNonPublicMethods(resource); }
@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 " + ")"; }
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 boolean isCreateUserResource() { return TenantUserApi.class.isAssignableFrom(this.method.getDeclaringResource().getResourceClass()) && this.method.getHttpMethod().equals(HttpMethod.POST) && this.method.getResource().getPath().getValue().endsWith("/api/user"); } }
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(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(); }
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(); }
static String getMetricBaseName(AbstractResourceMethod am) { String metricId = getPathWithoutSurroundingSlashes(am.getResource().getPath()); if (!metricId.isEmpty()) { metricId = "/" + metricId; } String httpMethod; if (am instanceof AbstractSubResourceMethod) { // if this is a subresource, add on the subresource's path component AbstractSubResourceMethod asrm = (AbstractSubResourceMethod) am; metricId += "/" + getPathWithoutSurroundingSlashes(asrm.getPath()); httpMethod = asrm.getHttpMethod(); } else { httpMethod = am.getHttpMethod(); } if (metricId.isEmpty()) { // this happens for WadlResource -- that case actually exists at "application.wadl" though metricId = "(no path)"; } metricId += " " + httpMethod; return metricId; }
@Override public Resource createResource( AbstractResource r, String path ) { Resource wadlResource = new Resource(); if (path != null) wadlResource.setPath(path); else if (r.isRootResource()) wadlResource.setPath(r.getPath().getValue()); return wadlResource; }
@Override public Resource createResource( AbstractResource r, String path ) { Resource wadlResource = new Resource(); if (path != null) wadlResource.setPath(path); else if (r.isRootResource()) wadlResource.setPath(r.getPath().getValue()); return wadlResource; }
AbstractResource superResource = IntrospectionModeller.createResource(singletons.getClass().getSuperclass()); String uriPrefix = getStringWithoutStartingSlash(resource.getPath().getValue());