public ContainerRequest filter(ContainerRequest request) { LOGGER.log(Level.INFO, "Sub-Resource Method matched." + "\n Path: " + asrm.getPath().getValue() + (context != null ? "\n Matched Result: " + context.getUriInfo().getMatchedResults().get(0) : "") + "\n HttpMethod: " + asrm.getHttpMethod() + "\n Resource: " + asrm.getDeclaringResource().getResourceClass().getName() + "\n Method: " + asrm.getMethod().toGenericString()); return request; } }
final AbstractSubResourceMethod abstractSubResourceMethod = new AbstractSubResourceMethod( resource, m.getMethod(), addProduces(m, abstractSubResourceMethod, classScopeProducesAnnotation); processParameters( abstractSubResourceMethod.getResource().getResourceClass(), abstractSubResourceMethod.getMethod().getDeclaringClass(), abstractSubResourceMethod, m, isEncoded);
@Override public void visitAbstractSubResourceMethod(AbstractSubResourceMethod method) { // check the same things that are being checked for resource methods visitAbstractResourceMethod(method); // and make sure the Path is not null if ((null == method.getPath()) || (null == method.getPath().getValue()) || (method.getPath().getValue().length() == 0)) { issueList.add(new ResourceModelIssue( method, ImplMessages.ERROR_SUBRES_METHOD_URI_PATH_INVALID(method.getMethod(), method.getPath()), true)); } }
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; }
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()); } } }
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; }
for (AbstractSubResourceMethod m : r.getSubResourceMethods()) { String template = m.getPath().getValue(); Resource wadlSubResource = wadlSubResources.get(template); Map<String, Param> wadlSubResourceParams = wadlSubResourcesParams.get(template);
public ContainerRequest filter(ContainerRequest request) { LOGGER.log(Level.INFO, "Sub-Resource Method matched." + "\n Path: " + asrm.getPath().getValue() + (context != null ? "\n Matched Result: " + context.getUriInfo().getMatchedResults().get(0) : "") + "\n HttpMethod: " + asrm.getHttpMethod() + "\n Resource: " + asrm.getDeclaringResource().getResourceClass().getName() + "\n Method: " + asrm.getMethod().toGenericString()); return request; } }
@Override public void visitAbstractSubResourceMethod(AbstractSubResourceMethod method) { // check the same things that are being checked for resource methods visitAbstractResourceMethod(method); // and make sure the Path is not null if ((null == method.getPath()) || (null == method.getPath().getValue()) || (method.getPath().getValue().length() == 0)) { issueList.add(new ResourceModelIssue( method, ImplMessages.ERROR_SUBRES_METHOD_URI_PATH_INVALID(method.getMethod(), method.getPath()), true)); } }
@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(); }
final AbstractSubResourceMethod abstractSubResourceMethod = new AbstractSubResourceMethod( resource, m.getMethod(), addProduces(m, abstractSubResourceMethod, classScopeProducesAnnotation); processParameters( abstractSubResourceMethod.getResource().getResourceClass(), abstractSubResourceMethod.getMethod().getDeclaringClass(), abstractSubResourceMethod, m, isEncoded);
public ContainerRequest filter(ContainerRequest request) { LOGGER.log(Level.INFO, "Sub-Resource Method matched." + "\n Path: " + asrm.getPath().getValue() + (context != null ? "\n Matched Result: " + context.getUriInfo().getMatchedResults().get(0) : "") + "\n HttpMethod: " + asrm.getHttpMethod() + "\n Resource: " + asrm.getDeclaringResource().getResourceClass().getName() + "\n Method: " + asrm.getMethod().toGenericString()); return request; } }
@Override public void visitAbstractSubResourceMethod(AbstractSubResourceMethod method) { // check the same things that are being checked for resource methods visitAbstractResourceMethod(method); // and make sure the Path is not null if ((null == method.getPath()) || (null == method.getPath().getValue()) || (method.getPath().getValue().length() == 0)) { issueList.add(new ResourceModelIssue( method, ImplMessages.ERROR_SUBRES_METHOD_URI_PATH_INVALID(method.getMethod(), method.getPath()), true)); } }
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; }
final AbstractSubResourceMethod abstractSubResourceMethod = new AbstractSubResourceMethod( resource, m.getMethod(), addProduces(m, abstractSubResourceMethod, classScopeProducesAnnotation); processParameters( abstractSubResourceMethod.getResource().getResourceClass(), abstractSubResourceMethod.getMethod().getDeclaringClass(), abstractSubResourceMethod, m, isEncoded);
String superSrmPath = getStringWithoutStartingSlash(superSrm.getPath().getValue()); Class<?> superSrmClass = superSrm.getDeclaringResource().getResourceClass(); if(srmClass.getSuperclass().equals(superSrmClass) && !srm.getMethod().getName().equals(superSrm.getMethod().getName())){ String uri = uriPrefix + "/" + srmPath + "/" + superSrmPath ; resources.put(uri,superSrm.getHttpMethod()); LOG.info("Found http method " +superSrm.getHttpMethod() + " for the path " + uri + " returning (class) " + superSrm.getReturnType().getName());