Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

So, let's take a look at one as an example -- ListStaticEntriesResource. This and all of these URI-handler classes must extend ServerResource and have whatever functions we define in them. We do not need to override any functions or name any functions in a special way. However, we must annotate functions with the HTTP command they are to process. We can annotate with @Get, @Post, @Put, @Delete for the common HTTP commands (there are others though). @Get is demonstrated in our ListStaticEntriesResource example here and below.

Code Block
languagejava
public class ListStaticEntriesResource extends ServerResource {
    protected static Logger log = LoggerFactory.getLogger(ListStaticEntriesResource.class);
    
    @Get("json")
    public SFPEntryMap ListStaticEntries() {
        IStaticEntryPusherService sfpService =
                (IStaticEntryPusherService)getContext().getAttributes().
                    get(IStaticEntryPusherService.class.getCanonicalName());

        String param = (String) getRequestAttributes().get("switch");
        if (log.isDebugEnabled())
            log.debug("Listing all static entires for switch: " + param);
        if (param.toLowerCase().equals("all")) {
            return new SFPEntryMap(sfpService.getFlows());
        } else {
            try {
                Map<String, Map<String, OFMessage>> retMap = new HashMap<String, Map<String, OFMessage>>();
                retMap.put(param, sfpService.getEntries(DatapathId.of(param)));
                return new SFPEntryMap(retMap);
            } catch (NumberFormatException e){
                setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ControllerSwitchesResource.DPID_ERROR);
            }
        }
        return null;
    }
}

...