1 download jackson, restlet lib
2 create AntiDDoSResource extending ServerResource
public class AntiDDoSResource extends ServerResource { @Get("json") public Object handleRequest() { ISecurityAppProviderService service = (ISecurityAppProviderService)getContext().getAttributes(). get(ISecurityAppProviderService.class.getCanonicalName()); String op = (String) getRequestAttributes().get("op"); String obj = (String) getRequestAttributes().get("obj"); // REST API check status if (op.equalsIgnoreCase("status")) { if (service.isEnabled()) return "{\"result\" : \"ADS enabled\"}"; else return "{\"result\" : \"ADS disabled\"}"; } // REST API enable firewall if (op.equalsIgnoreCase("enable")) { service.run(); return "{\"status\" : \"success\", \"details\" : \"ADS running\"}"; } // REST API disable firewall if (op.equalsIgnoreCase("disable")) { service.terminate(); return "{\"status\" : \"success\", \"details\" : \"ADS stopped\"}"; } // no known options found return "{\"status\" : \"failure\", \"details\" : \"invalid operation: "+op+"/"+obj+"\"}"; }
3 create a ADSWebRoutable class implementing RestletRoutable
public class ADSWebRoutable implements RestletRoutable {
@Override
public Router getRestlet(Context context) {
Router router = new Router(context);
router.attach("/{op}/json", AntiDDoSResource.class);
router.attach("/{op}/{obj}/json", AntiDDoSResource.class);
return router;
}/**
* Set the base path for the Firewall
*/
@Override
public String basePath() {
return "/app/ads";
}
}
3 bind the ADSWebRoutable with