Java Code Examples for org.restlet.Context

The following are top voted examples for showing how to use org.restlet.Context. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: restlet-framework   File: AnnotationInfo.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the actual type for a given generic type.
 * 
 * @param initialType
 *            The initial type, which may be generic.
 * @param genericType
 *            The generic type information if any.
 * @return The actual type.
 */
protected Class<?> getJavaActualType(Class<?> initialType, Type genericType) {
    Class<?> result = initialType;

    try {
        if (genericType instanceof TypeVariable<?>) {
            TypeVariable<?> genericTypeVariable = (TypeVariable<?>) genericType;
            String genericTypeName = genericTypeVariable.getName();
            result = getJavaActualType(getJavaClass(), genericTypeName);
        }
    } catch (Throwable t) {
        Context.getCurrentLogger().warn("Cannot get actual type of generic type: " + genericType, t);
    }

    return result;
}
 
Example 2
Project: restlet-framework   File: HeaderUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Adds extension headers if they are non-standard headers.
 * 
 * @param existingHeaders
 *            The headers to update.
 * @param additionalHeaders
 *            The headers to add.
 */
public static void addExtensionHeaders(Series<Header> existingHeaders,
        Series<Header> additionalHeaders) {
    if (additionalHeaders != null) {
        for (Header param : additionalHeaders) {
            if (STANDARD_HEADERS.contains(param.getName())) {
                // Standard headers that can't be overridden
                Context.getCurrentLogger()
                        .warn(
                                "Addition of the standard header \""
                                        + param.getName()
                                        + "\" is not allowed. Please use the equivalent property in the Restlet API.");
            } else if (UNSUPPORTED_STANDARD_HEADERS.contains(param
                    .getName())) {
                Context.getCurrentLogger()
                        .warn(
                                "Addition of the standard header \""
                                        + param.getName()
                                        + "\" is discouraged as a future version of the Restlet API will directly support it.");
                existingHeaders.add(param);
            } else {
                existingHeaders.add(param);
            }
        }
    }
}
 
Example 3
Project: restlet-framework   File: FormUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Parses a post into a given entries series.
 * 
 * @param entries
 *            The target entries series.
 * @param post
 *            The posted form.
 */
public static void parse(Series<FormData> entries, Representation post) {
    if (post != null) {
        if (post.isAvailable()) {
            FormReader fr = null;

            try {
                fr = new FormReader(post);
            } catch (IOException ioe) {
                Context.getCurrentLogger().warn("Unable to create a form reader. Parsing aborted.", ioe);
            }

            if (fr != null) {
                fr.addEntries(entries);
            }
        } else {
            throw new IllegalStateException(
                    "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
        }
    }
}
 
Example 4
Project: floodlight-hardware   File: CoreWebRoutable.java   Source Code and License 6 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/module/all/json", ModuleLoaderResource.class);
    router.attach("/module/loaded/json", LoadedModuleLoaderResource.class);
    router.attach("/switch/{" + STR_SWITCH_ID + "}/role/json", SwitchRoleResource.class);
    router.attach("/switch/all/{" + STR_STAT_TYPE + "}/json", AllSwitchStatisticsResource.class);
    router.attach("/switch/{" + STR_SWITCH_ID + "}/{" + STR_STAT_TYPE + "}/json", SwitchStatisticsResource.class);
    router.attach("/controller/switches/json", ControllerSwitchesResource.class);
    router.attach("/counter/{" + STR_CTR_MODULE + "}/{" + STR_CTR_TITLE + "}/json", CounterResource.class);
    router.attach("/memory/json", ControllerMemoryResource.class);
    router.attach("/packettrace/json", PacketTraceResource.class);
    router.attach("/storage/tables/json", StorageSourceTablesResource.class);
    router.attach("/controller/summary/json", ControllerSummaryResource.class);
    router.attach("/role/json", ControllerRoleResource.class);
    router.attach("/health/json", HealthCheckResource.class);
    router.attach("/system/uptime/json", SystemUptimeResource.class);
    return router;
}
 
Example 5
Project: restlet-framework   File: Engine.java   Source Code and License 6 votes vote down vote up
/**
 * Registers a helper.
 *
 * @param classLoader      The classloader to use.
 * @param provider         Bynary name of the helper's class.
 * @param helpers          The list of helpers to update.
 * @param constructorClass The constructor parameter class to look for.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public void registerHelper(ClassLoader classLoader, String provider,
                           List helpers, Class constructorClass) {
    if ((provider != null) && (!provider.equals(""))) {
        // Instantiate the factory
        try {
            Class providerClass = classLoader.loadClass(provider);

            if (constructorClass == null) {
                helpers.add(providerClass.newInstance());
            } else {
                helpers.add(providerClass.getConstructor(constructorClass)
                        .newInstance(constructorClass.cast(null)));
            }
        } catch (Throwable t) {
            Context.getCurrentLogger().info("Unable to register the helper " + provider, t);
        }
    }
}
 
Example 6
Project: restlet-framework   File: Tag.java   Source Code and License 6 votes vote down vote up
/**
 * Parses a tag formatted as defined by the HTTP standard.
 * 
 * @param httpTag
 *            The HTTP tag string; if it starts with 'W/' the tag will be
 *            marked as weak and the data following the 'W/' used as the
 *            tag; otherwise it should be surrounded with quotes (e.g.,
 *            "sometag").
 * @return A new tag instance.
 * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11">HTTP Entity Tags</a>
 */
public static Tag parse(String httpTag) {
    Tag result = null;
    boolean weak = false;
    String httpTagCopy = httpTag;

    if (httpTagCopy.startsWith("W/")) {
        weak = true;
        httpTagCopy = httpTagCopy.substring(2);
    }

    if (httpTagCopy.startsWith("\"") && httpTagCopy.endsWith("\"")) {
        result = new Tag(
                httpTagCopy.substring(1, httpTagCopy.length() - 1), weak);
    } else if (httpTagCopy.equals("*")) {
        result = new Tag("*", weak);
    } else {
        Context.getCurrentLogger().warn("Invalid tag format detected: " + httpTagCopy);
    }

    return result;
}
 
Example 7
Project: QoS-floodlight   File: CoreWebRoutable.java   Source Code and License 6 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/module/all/json", ModuleLoaderResource.class);
    router.attach("/module/loaded/json", LoadedModuleLoaderResource.class);
    router.attach("/switch/{switchId}/role/json", SwitchRoleResource.class);
    router.attach("/switch/all/{statType}/json", AllSwitchStatisticsResource.class);
    router.attach("/switch/{switchId}/{statType}/json", SwitchStatisticsResource.class);
    router.attach("/controller/switches/json", ControllerSwitchesResource.class);
    router.attach("/counter/{counterTitle}/json", CounterResource.class);
    router.attach("/counter/{switchId}/{counterName}/json", SwitchCounterResource.class);
    router.attach("/counter/categories/{switchId}/{counterName}/{layer}/json", SwitchCounterCategoriesResource.class);
    router.attach("/memory/json", ControllerMemoryResource.class);
    router.attach("/packettrace/json", PacketTraceResource.class);
    router.attach("/storage/tables/json", StorageSourceTablesResource.class);
    router.attach("/controller/summary/json", ControllerSummaryResource.class);
    router.attach("/role/json", ControllerRoleResource.class);
    router.attach("/health/json", HealthCheckResource.class);
    router.attach("/system/uptime/json", SystemUptimeResource.class);
    return router;
}
 
Example 8
Project: restlet-framework   File: Finder.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new finder instance based on the "targetClass" property.
 * 
 * @param targetClass
 *            The target Resource class to attach.
 * @param finderClass
 *            The optional finder class to instantiate.
 * @param logger
 *            The logger.
 * @return The new finder instance.
 */
public static Finder createFinder(
        Class<? extends ServerResource> targetClass,
        Class<? extends Finder> finderClass, Context context, Logger logger) {
    Finder result = null;

    if (finderClass != null) {
        try {
            Constructor<? extends Finder> constructor = finderClass
                    .getConstructor(Context.class, Class.class);

            if (constructor != null) {
                result = constructor.newInstance(context, targetClass);
            }
        } catch (Exception e) {
            if (logger != null) {
                logger.warn("Exception while instantiating the finder.", e);
            }
        }
    } else {
        result = new Finder(context, targetClass);
    }

    return result;
}
 
Example 9
Project: restlet-framework   File: Reference.java   Source Code and License 6 votes vote down vote up
/**
 * Encodes a given string using the standard URI encoding mechanism and the
 * UTF-8 character set. Useful to prevent the usage of '+' to encode spaces
 * (%20 instead). The '*' characters are encoded as %2A and %7E are replaced
 * by '~'.
 * 
 * @param toEncode
 *            The string to encode.
 * @param queryString
 *            True if the string to encode is part of a query string instead
 *            of a HTML form post.
 * @param characterSet
 *            The supported character encoding.
 * @return The encoded string.
 */
public static String encode(String toEncode, boolean queryString, CharacterSet characterSet) {
    String result = null;

    try {
        result = (characterSet == null) ? toEncode : java.net.URLEncoder.encode(toEncode, characterSet.getName());

        if (result != null && queryString) {
            result = result.replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
        }
    } catch (UnsupportedEncodingException uee) {
        Context.getCurrentLogger()
                .warn("Unable to encode the string with the UTF-8 character set.", uee);
    }

    return result;
}
 
Example 10
Project: restlet-framework   File: JaxbRepresentation.java   Source Code and License 6 votes vote down vote up
/**
 * Writes the representation to a stream of characters.
 *
 * @param writer
 *            The writer to use when writing.
 *
 * @throws IOException
 *             If any error occurs attempting to write the stream.
 */
@Override
public void write(Writer writer) throws IOException {
    try {
        new Marshaller<T>(this, this.contextPath, getClassLoader())
                .marshal(getObject(), writer);
    } catch (JAXBException e) {
        Context.getCurrentLogger().warn("JAXB marshalling error caught.", e);

        // Maybe the tree represents a failure, try that.
        try {
            new Marshaller<T>(this, "failure", getClassLoader()).marshal(
                    getObject(), writer);
        } catch (JAXBException e2) {
            // We don't know what package this tree is from.
            throw new IOException(e.getMessage());
        }
    }
}
 
Example 11
Project: springboot-shiro-cas-mybatis   File: TicketGrantingTicketResource.java   Source Code and License 5 votes vote down vote up
@Override
public void init(final Context context, final Request request, final Response response) {
    super.init(context, request, response);
    this.ticketGrantingTicketId = (String) request.getAttributes().get("ticketGrantingTicketId");
    this.setNegotiated(false);
    this.getVariants().add(new Variant(MediaType.APPLICATION_WWW_FORM));
}
 
Example 12
Project: floodlight-simple-multicast   File: MulticastWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
	Router router = new Router(context);
	router.attach("/controller/summary/json", ControllerSummaryResource.class);
	router.attach("/module/loaded/json", LoadedModuleLoaderResource.class);
	router.attach("/controller/switches/json", ControllerSwitchesResource.class);
	router.attach("/groups_info/json", GroupsInfoResource.class);
	router.attach("/group_info/json", GroupInfoResource.class);
	router.attach("/group_create/json", GroupCreateResource.class);
	return router;
}
 
Example 13
Project: open-kilda   File: SwitchManagerWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/flow", FlowResource.class);
    router.attach("/flows/switch_id/{switch_id}", FlowsResource.class);
    router.attach("/meters/switch_id/{switch_id}", MetersResource.class);
    return router;
}
 
Example 14
Project: fresco_floodlight   File: PerfWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/data/json", PerfMonDataResource.class);
    router.attach("/{perfmonstate}/json", PerfMonToggleResource.class); // enable, disable, or reset
    return router;
}
 
Example 15
Project: fresco_floodlight   File: DeviceRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/all/json", DeviceResource.class);
    router.attach("/", DeviceResource.class);
    router.attach("/debug", DeviceEntityResource.class);
    return router;
}
 
Example 16
Project: fresco_floodlight   File: VirtualNetworkWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/tenants/{tenant}/networks", NetworkResource.class); // GET
    router.attach("/tenants/{tenant}/networks/{network}", NetworkResource.class); // PUT, DELETE
    router.attach("/tenants/{tenant}/networks", NetworkResource.class); // POST
    router.attach("/tenants/{tenant}/networks/{network}/ports/{port}/attachment", HostResource.class);
    router.attachDefault(NoOp.class);
    return router;
}
 
Example 17
Project: fresco_floodlight   File: LinkDiscoveryWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/autoportfast/{state}/json", AutoPortFast.class); // enable/true or disable/false
    return router;
}
 
Example 18
Project: fresco_floodlight   File: LoadBalancerWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/vips/", VipsResource.class); // GET, POST
    router.attach("/vips/{vip}", VipsResource.class); // GET, PUT, DELETE 
    router.attach("/pools/", PoolsResource.class); // GET, POST
    router.attach("/pools/{pool}", PoolsResource.class); // GET, PUT, DELETE
    router.attach("/members/", MembersResource.class); // GET, POST
    router.attach("/members/{member}", MembersResource.class); // GET, PUT, DELETE
    router.attach("/pools/{pool}/members", PoolMemberResource.class); //GET
    router.attach("/health_monitors/", MonitorsResource.class); //GET, POST
    router.attach("/health_monitors/{monitor}", MonitorsResource.class); //GET, PUT, DELETE        
    router.attachDefault(NoOp.class);
    return router;
 }
 
Example 19
Project: fresco_floodlight   File: StaticWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
       Router router = new Router(context);
       router.attach("", new Directory(context, "clap://classloader/web/"));
       context.setClientDispatcher(new Client(context, Protocol.CLAP));
       return router;
}
 
Example 20
Project: fresco_floodlight   File: ACLWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
    * Create the Restlet router and bind to the proper resources.
    */
@Override
public Restlet getRestlet(Context context) {
       Router router = new Router(context);
       router.attach("/rules/json", ACLRuleResource.class);
       router.attach("/clear/json", ClearACRulesResource.class);
       return router;
}
 
Example 21
Project: fresco_floodlight   File: StaticFlowEntryWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/json", StaticFlowEntryPusherResource.class);
    router.attach("/json/store", StaticFlowEntryPusherResource.class);
    router.attach("/json/delete", StaticFlowEntryDeleteResource.class);
    router.attach("/clear/{switch}/json", ClearStaticFlowEntriesResource.class);
    router.attach("/list/{switch}/json", ListStaticFlowEntriesResource.class);
    return router;
}
 
Example 22
Project: fresco_floodlight   File: TopologyWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/links/json", LinksResource.class);
    router.attach("/directed-links/json", DirectedLinksResource.class);
    router.attach("/external-links/json", ExternalLinksResource.class);
    router.attach("/tunnellinks/json", TunnelLinksResource.class);
    router.attach("/switchclusters/json", SwitchClustersResource.class);
    router.attach("/broadcastdomainports/json", BroadcastDomainPortsResource.class);
    router.attach("/enabledports/json", EnabledPortsResource.class);
    router.attach("/blockedports/json", BlockedPortsResource.class);
    router.attach("/route/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json", RouteResource.class);
    return router;
}
 
Example 23
Project: fresco_floodlight   File: SwitchStatisticsWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/bandwidth/{" + DPID_STR + "}/{" + PORT_STR + "}/json", BandwidthResource.class);
    router.attach("/config/enable/json", ConfigResource.class);
    router.attach("/config/disable/json", ConfigResource.class);
    return router;
}
 
Example 24
Project: fresco_floodlight   File: FirewallWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/module/status/json",       FirewallStatusResource.class);
    router.attach("/module/enable/json",       FirewallEnableResource.class);
    router.attach("/module/disable/json",      FirewallDisableResource.class);
    router.attach("/module/subnet-mask/json",  FirewallSubnetMaskResource.class);
    router.attach("/module/storageRules/json", FirewallStorageRulesResource.class);

    router.attach("/rules/json",               FirewallRulesResource.class);

    return router;
}
 
Example 25
Project: fresco_floodlight   File: CoreWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/module/all/json", ModuleLoaderResource.class);
    router.attach("/module/loaded/json", LoadedModuleLoaderResource.class);
    router.attach("/switch/{" + STR_SWITCH_ID + "}/role/json", SwitchRoleResource.class);
    router.attach("/switch/all/{" + STR_STAT_TYPE + "}/json", AllSwitchStatisticsResource.class);
    router.attach("/switch/{" + STR_SWITCH_ID + "}/{" + STR_STAT_TYPE + "}/json", SwitchStatisticsResource.class);
    router.attach("/controller/switches/json", ControllerSwitchesResource.class);
    router.attach("/counter/{" + STR_CTR_MODULE + "}/{" + STR_CTR_TITLE + "}/json", CounterResource.class);
    router.attach("/memory/json", ControllerMemoryResource.class);
    router.attach("/packettrace/json", PacketTraceResource.class);
    router.attach("/storage/tables/json", StorageSourceTablesResource.class);
    router.attach("/controller/summary/json", ControllerSummaryResource.class);
    router.attach("/role/json", ControllerRoleResource.class);
    router.attach("/health/json", HealthCheckResource.class);
    router.attach("/system/uptime/json", SystemUptimeResource.class);
    return router;
}
 
Example 26
Project: fresco_floodlight   File: ACLRuleResourceTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testRemove(){
	ACL s = new ACL();
       FloodlightModuleContext fmc = new FloodlightModuleContext();
	try {
		s.init(fmc);
	} catch (FloodlightModuleException e) {
		e.printStackTrace();
	}
	
	ACLRuleResource r = new ACLRuleResource();
	Context ctx = new Context();
	r.init(ctx, null, null);
	r.getContext().getAttributes().putIfAbsent(IACLService.class.getCanonicalName(), s);

	// input a valid JSON string
       String json = "{\"nw-proto\":\"TCP\",\"src-ip\":\"10.0.0.1/32\",\"dst-ip\": \"10.0.0.2/32\",\"tp-dst\":\"80\",\"action\":\"ALLOW\"}";
       assertEquals(r.store(json),"{\"status\" : \"" + "Success! New rule added." + "\"}");
       
       // input a invalid JSON string that contains a invalid ruleid value
       json = "{\"ruleid\":\"a\"}";
       assertEquals(r.remove(json),"{\"status\" : \"" + "Failed! ruleid must be specified as a number." + "\"}");
       
       // input a invalid JSON string that contains a non-existing ruleid value
       json = "{\"ruleid\":\"2\"}";
       assertEquals(r.remove(json),"{\"status\" : \"" + "Failed! a rule with this ID doesn't exist." + "\"}");
       
       // input a valid JSON string that removes an existing ACL rule
       json = "{\"ruleid\":\"1\"}";
       assertEquals(r.remove(json),"{\"status\" : \"" + "Success! Rule deleted" + "\"}");
       
}
 
Example 27
Project: iTAP-controller   File: ObfuscationRestApiWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/masks/json", ObfuscationRestApiResourceMasks.class);
    router.attach("/links/json", ObfuscationRestApiResourceLinks.class);
    //router.attach("/tm/json", ObfuscationRestApiResourceTrafficMatrix.class);
    return router;
}
 
Example 28
Project: iTAP-controller   File: PerfWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/data/json", PerfMonDataResource.class);
    router.attach("/{perfmonstate}/json", PerfMonToggleResource.class); // enable, disable, or reset
    return router;
}
 
Example 29
Project: iTAP-controller   File: DeviceRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/all/json", DeviceResource.class);
    router.attach("/", DeviceResource.class);
    router.attach("/debug", DeviceEntityResource.class);
    return router;
}
 
Example 30
Project: iTAP-controller   File: VirtualNetworkWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/tenants/{tenant}/networks", NetworkResource.class); // GET
    router.attach("/tenants/{tenant}/networks/{network}", NetworkResource.class); // PUT, DELETE
    router.attach("/tenants/{tenant}/networks", NetworkResource.class); // POST
    router.attach("/tenants/{tenant}/networks/{network}/ports/{port}/attachment", HostResource.class);
    router.attachDefault(NoOp.class);
    return router;
}
 
Example 31
Project: iTAP-controller   File: LinkDiscoveryWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/autoportfast/{state}/json", AutoPortFast.class); // enable/true or disable/false
    return router;
}
 
Example 32
Project: iTAP-controller   File: LoadBalancerWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/vips/", VipsResource.class); // GET, POST
    router.attach("/vips/{vip}", VipsResource.class); // GET, PUT, DELETE 
    router.attach("/pools/", PoolsResource.class); // GET, POST
    router.attach("/pools/{pool}", PoolsResource.class); // GET, PUT, DELETE
    router.attach("/members/", MembersResource.class); // GET, POST
    router.attach("/members/{member}", MembersResource.class); // GET, PUT, DELETE
    router.attach("/pools/{pool}/members", PoolMemberResource.class); //GET
    router.attach("/health_monitors/", MonitorsResource.class); //GET, POST
    router.attach("/health_monitors/{monitor}", MonitorsResource.class); //GET, PUT, DELETE        
    router.attachDefault(NoOp.class);
    return router;
 }
 
Example 33
Project: iTAP-controller   File: StaticWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
       Router router = new Router(context);
       router.attach("", new Directory(context, "clap://classloader/web/"));
       context.setClientDispatcher(new Client(context, Protocol.CLAP));
       return router;
}
 
Example 34
Project: iTAP-controller   File: ACLWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
    * Create the Restlet router and bind to the proper resources.
    */
@Override
public Restlet getRestlet(Context context) {
       Router router = new Router(context);
       router.attach("/rules/json", ACLRuleResource.class);
       router.attach("/clear/json", ClearACRulesResource.class);
       return router;
}
 
Example 35
Project: iTAP-controller   File: StaticFlowEntryWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/json", StaticFlowEntryPusherResource.class);
    router.attach("/json/store", StaticFlowEntryPusherResource.class);
    router.attach("/json/delete", StaticFlowEntryDeleteResource.class);
    router.attach("/clear/{switch}/json", ClearStaticFlowEntriesResource.class);
    router.attach("/list/{switch}/json", ListStaticFlowEntriesResource.class);
    return router;
}
 
Example 36
Project: iTAP-controller   File: TopologyWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/links/json", LinksResource.class);
    router.attach("/directed-links/json", DirectedLinksResource.class);
    router.attach("/external-links/json", ExternalLinksResource.class);
    router.attach("/tunnellinks/json", TunnelLinksResource.class);
    router.attach("/switchclusters/json", SwitchClustersResource.class);
    router.attach("/broadcastdomainports/json", BroadcastDomainPortsResource.class);
    router.attach("/enabledports/json", EnabledPortsResource.class);
    router.attach("/blockedports/json", BlockedPortsResource.class);
    router.attach("/route/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json", RouteResource.class);
    return router;
}
 
Example 37
Project: iTAP-controller   File: FirewallWebRoutable.java   Source Code and License 5 votes vote down vote up
/**
 * Create the Restlet router and bind to the proper resources.
 */
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/module/status/json",       FirewallStatusResource.class);
    router.attach("/module/enable/json",       FirewallEnableResource.class);
    router.attach("/module/disable/json",      FirewallDisableResource.class);
    router.attach("/module/subnet-mask/json",  FirewallSubnetMaskResource.class);
    router.attach("/module/storageRules/json", FirewallStorageRulesResource.class);

    router.attach("/rules/json",               FirewallRulesResource.class);

    return router;
}
 
Example 38
Project: iTAP-controller   File: CoreWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Restlet getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/module/all/json", ModuleLoaderResource.class);
    router.attach("/module/loaded/json", LoadedModuleLoaderResource.class);
    router.attach("/switch/{" + STR_SWITCH_ID + "}/role/json", SwitchRoleResource.class);
    router.attach("/switch/all/{" + STR_STAT_TYPE + "}/json", AllSwitchStatisticsResource.class);
    router.attach("/switch/{" + STR_SWITCH_ID + "}/{" + STR_STAT_TYPE + "}/json", SwitchStatisticsResource.class);
    router.attach("/controller/switches/json", ControllerSwitchesResource.class);
    router.attach("/counter/{" + STR_CTR_MODULE + "}/{" + STR_CTR_TITLE + "}/json", CounterResource.class);
    router.attach("/memory/json", ControllerMemoryResource.class);
    router.attach("/packettrace/json", PacketTraceResource.class);
    router.attach("/storage/tables/json", StorageSourceTablesResource.class);
    router.attach("/controller/summary/json", ControllerSummaryResource.class);
    router.attach("/role/json", ControllerRoleResource.class);
    router.attach("/health/json", HealthCheckResource.class);
    router.attach("/system/uptime/json", SystemUptimeResource.class);
    return router;
}
 
Example 39
Project: iTAP-controller   File: ACLRuleResourceTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testRemove(){
	ACL s = new ACL();
       FloodlightModuleContext fmc = new FloodlightModuleContext();
	try {
		s.init(fmc);
	} catch (FloodlightModuleException e) {
		e.printStackTrace();
	}
	
	ACLRuleResource r = new ACLRuleResource();
	Context ctx = new Context();
	r.init(ctx, null, null);
	r.getContext().getAttributes().putIfAbsent(IACLService.class.getCanonicalName(), s);

	// input a valid JSON string
       String json = "{\"nw-proto\":\"TCP\",\"src-ip\":\"10.0.0.1/32\",\"dst-ip\": \"10.0.0.2/32\",\"tp-dst\":\"80\",\"action\":\"ALLOW\"}";
       assertEquals(r.store(json),"{\"status\" : \"" + "Success! New rule added." + "\"}");
       
       // input a invalid JSON string that contains a invalid ruleid value
       json = "{\"ruleid\":\"a\"}";
       assertEquals(r.remove(json),"{\"status\" : \"" + "Failed! ruleid must be specified as a number." + "\"}");
       
       // input a invalid JSON string that contains a non-existing ruleid value
       json = "{\"ruleid\":\"2\"}";
       assertEquals(r.remove(json),"{\"status\" : \"" + "Failed! a rule with this ID doesn't exist." + "\"}");
       
       // input a valid JSON string that removes an existing ACL rule
       json = "{\"ruleid\":\"1\"}";
       assertEquals(r.remove(json),"{\"status\" : \"" + "Success! Rule deleted" + "\"}");
       
}
 
Example 40
Project: floodlight-hardware   File: SwitchStatisticsWebRoutable.java   Source Code and License 5 votes vote down vote up
@Override
public Router getRestlet(Context context) {
    Router router = new Router(context);
    router.attach("/bandwidth/{" + DPID_STR + "}/{" + PORT_STR + "}/json", BandwidthResource.class);
    router.attach("/config/enable/json", ConfigResource.class);
    router.attach("/config/disable/json", ConfigResource.class);
    return router;
}