HmsNodeRateLimiterFilter implements ContainerRequestFilter, ContainerResponseFilter { public String extractNodeIdFromURI( String requestURI, EventComponent component ) { if ( requestURI != null && component != null ) { String subStringContainingNodeId = null; if ( EventComponent.SWITCH.equals( component ) ) { subStringContainingNodeId = StringUtils.substringAfter( requestURI, "/switches/" ); } else if ( EventComponent.SERVER.equals( component ) ) { subStringContainingNodeId = StringUtils.substringAfter( requestURI, "/host/" ); } else { logger.debug( "Component not supported while extracting nodeId from Request URI: {} ", requestURI ); return null; } if ( subStringContainingNodeId != null && subStringContainingNodeId.length() != 0 ) { return extractNodeId( subStringContainingNodeId ); } } return null; }  @Override void filter( ContainerRequestContext reqCtx, ContainerResponseContext rspCtx ); @Override void filter( ContainerRequestContext reqCtx ); String extractNodeIdFromEventURI( String requestURI ); String extractNodeIdFromURI( String requestURI, EventComponent component ); String extractNodeId( String uri );  }
@Test public void extractNodeIdFromURITestForNode() { HmsNodeRateLimiterFilter hmsNodeRateLimiterFilter = new HmsNodeRateLimiterFilter(); String nodeId = hmsNodeRateLimiterFilter.extractNodeIdFromURI( "api/1.0/hms/host/N1/powerstatus/", EventComponent.SERVER ); assertNotNull( nodeId ); assertEquals( nodeId, "N1" ); }
@Test public void extractNodeIdFromURITestForSwitch() { HmsNodeRateLimiterFilter hmsNodeRateLimiterFilter = new HmsNodeRateLimiterFilter(); String nodeId = hmsNodeRateLimiterFilter.extractNodeIdFromURI( "api/1.0/hms/switches/S1/", EventComponent.SWITCH ); assertNotNull( nodeId ); assertEquals( nodeId, "S1" ); }