{"id":450,"date":"2013-07-01T14:35:10","date_gmt":"2013-07-01T06:35:10","guid":{"rendered":"http:\/\/blog.marvelplanet.tk\/?p=450"},"modified":"2013-07-01T14:35:28","modified_gmt":"2013-07-01T06:35:28","slug":"floodlight-rest-module","status":"publish","type":"post","link":"https:\/\/marvelliu.space\/?p=450","title":{"rendered":"Floodlight REST module"},"content":{"rendered":"<p>1 download jackson, restlet lib<\/p>\n<p>2 create AntiDDoSResource extending ServerResource <\/p>\n<pre class=\"java\" name=\"code\">\r\npublic class AntiDDoSResource extends ServerResource {\r\n\r\n\t@Get(\"json\")\r\n    public Object handleRequest() {\r\n\t\tISecurityAppProviderService service = \r\n                (ISecurityAppProviderService)getContext().getAttributes().\r\n                get(ISecurityAppProviderService.class.getCanonicalName());\r\n\r\n        String op = (String) getRequestAttributes().get(\"op\");\r\n        String obj = (String) getRequestAttributes().get(\"obj\");\r\n\r\n        \/\/ REST API check status\r\n        if (op.equalsIgnoreCase(\"status\")) {\r\n            if (service.isEnabled())\r\n                return \"{\\\"result\\\" : \\\"ADS enabled\\\"}\";\r\n            else\r\n                return \"{\\\"result\\\" : \\\"ADS disabled\\\"}\";\r\n        }\r\n\r\n        \/\/ REST API enable firewall\r\n        if (op.equalsIgnoreCase(\"enable\")) {\r\n        \tservice.run();\r\n            return \"{\\\"status\\\" : \\\"success\\\", \\\"details\\\" : \\\"ADS running\\\"}\";\r\n        } \r\n        \r\n        \/\/ REST API disable firewall\r\n        if (op.equalsIgnoreCase(\"disable\")) {\r\n            service.terminate();\r\n            return \"{\\\"status\\\" : \\\"success\\\", \\\"details\\\" : \\\"ADS stopped\\\"}\";\r\n        } \r\n\r\n        \/\/ no known options found\r\n        return \"{\\\"status\\\" : \\\"failure\\\", \\\"details\\\" : \\\"invalid operation: \"+op+\"\/\"+obj+\"\\\"}\";\r\n    }\r\n<\/pre>\n<p>3 create a ADSWebRoutable class implementing RestletRoutable<\/p>\n<pre class=\"java\" name=\"code\">\npublic class ADSWebRoutable implements RestletRoutable {<br \/>\n    @Override<br \/>\n    public Router getRestlet(Context context) {<br \/>\n        Router router = new Router(context);<br \/>\n        router.attach(\"\/{op}\/json\", AntiDDoSResource.class);<br \/>\n        router.attach(\"\/{op}\/{obj}\/json\", AntiDDoSResource.class);<br \/>\n        return router;<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * Set the base path for the Firewall<br \/>\n     *\/<br \/>\n    @Override<br \/>\n    public String basePath() {<br \/>\n        return \"\/app\/ads\";<br \/>\n    }<br \/>\n}<br \/>\n<\/code><\/p>\n<p>3 bind the ADSWebRoutable with <\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 download jackson, restlet lib 2 create AntiDDoSResource extending ServerResource public class AntiDDoSResource extends ServerResource { @Get(&#8220;json&#8221;) public Object handleRequest() { ISecurityAppProviderService service = (ISecurityAppProviderService)getContext().getAttributes(). get(ISecurityAppProviderService.class.getCanonicalName()); String op = (String) getRequestAttributes().get(&#8220;op&#8221;); String obj = (String) getRequestAttributes().get(&#8220;obj&#8221;); \/\/ REST API check status if (op.equalsIgnoreCase(&#8220;status&#8221;)) { if (service.isEnabled()) return &#8220;{\\&#8221;result\\&#8221; : \\&#8221;ADS enabled\\&#8221;}&#8221;; else return &#8220;{\\&#8221;result\\&#8221; : &hellip; <a href=\"https:\/\/marvelliu.space\/?p=450\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Floodlight REST module&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[28,34],"class_list":["post-450","post","type-post","status-publish","format-standard","hentry","category-sdn","tag-floodight","tag-sdn"],"_links":{"self":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=450"}],"version-history":[{"count":6,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/450\/revisions"}],"predecessor-version":[{"id":457,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/450\/revisions\/457"}],"wp:attachment":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}