/** * Returns the number of Uri-Query options (i.e., arguments). * @return the count */ public int getURIQueryCount() { return getUriQuery().size(); }
/** * Removes a specific argument from the Uri-Query options. * Returns the current OptionSet object for a fluent API. * @param argument the argument to remove * @return this OptionSet */ public OptionSet removeUriQuery(String argument) { getUriQuery().remove(argument); return this; }
/** * Removes all Uri-Query options. * Returns the current OptionSet object for a fluent API. * @return this OptionSet */ public OptionSet clearUriQuery() { getUriQuery().clear(); return this; }
/** * Removes a specific argument from the Uri-Query options. * Returns the current OptionSet object for a fluent API. * @param argument the argument to remove * @return this OptionSet */ public OptionSet removeUriQuery(String argument) { getUriQuery().remove(argument); return this; }
/** * Removes all Uri-Query options. * Returns the current OptionSet object for a fluent API. * @return this OptionSet */ public OptionSet clearUriQuery() { getUriQuery().clear(); return this; }
/** * Returns the number of Uri-Query options (i.e., arguments). * @return the count */ public int getURIQueryCount() { return getUriQuery().size(); }
/** * Adds an argument to the Uri-Query options. * Returns the current OptionSet object for a fluent API. * @param argument the argument to add * @return this OptionSet */ public OptionSet addUriQuery(String argument) { if (argument == null) throw new NullPointerException("Uri-Query option must not be null"); if (argument.getBytes(CoAP.UTF8_CHARSET).length > 255) throw new IllegalArgumentException("Uri-Query option must be smaller or euqal to 255 bytes (UTF-8 encoded): " + argument); getUriQuery().add(argument); return this; }
/** * Adds an argument to the Uri-Query options. * Returns the current OptionSet object for a fluent API. * @param argument the argument to add * @return this OptionSet */ public OptionSet addUriQuery(String argument) { if (argument == null) throw new NullPointerException("Uri-Query option must not be null"); if (argument.getBytes(CoAP.UTF8_CHARSET).length > 255) throw new IllegalArgumentException("Uri-Query option must be smaller or euqal to 255 bytes (UTF-8 encoded): " + argument); getUriQuery().add(argument); return this; }
/** * Returns the Uri-Query options as &-separated query string. * @return the Uri-Query as string */ public String getUriQueryString() { StringBuilder builder = new StringBuilder(); for (String query:getUriQuery()) builder.append(query).append("&"); if (builder.length() > 0) builder.delete(builder.length() - 1, builder.length()); return builder.toString(); }
/** * Returns the Uri-Query options as &-separated query string. * @return the Uri-Query as string */ public String getUriQueryString() { StringBuilder builder = new StringBuilder(); for (String query:getUriQuery()) builder.append(query).append("&"); if (builder.length() > 0) builder.delete(builder.length() - 1, builder.length()); return builder.toString(); }
private void parseUriQuery() { if (getRequestOptions().getURIQueryCount() > 0) { queryParameters = new HashMap<>(); for (String param : getRequestOptions().getUriQuery()) { addParameter(param); } } }
/** * Responds with a list of all resources of the server, i.e. links. * * @param exchange the exchange */ @Override public void handleGET(CoapExchange exchange) { List<String> query = exchange.getRequestOptions().getUriQuery(); if (query.size() <= 1) { String tree = discoverTree(root, query); exchange.respond(ResponseCode.CONTENT, tree, MediaTypeRegistry.APPLICATION_LINK_FORMAT); } else { exchange.respond(ResponseCode.BAD_OPTION, "only one search query is supported!", MediaTypeRegistry.TEXT_PLAIN); } }
/** * Responds with a list of all resources of the server, i.e. links. * * @param exchange the exchange */ @Override public void handleGET(CoapExchange exchange) { List<String> query = exchange.getRequestOptions().getUriQuery(); if (query.size() <= 1) { String tree = discoverTree(root, query); exchange.respond(ResponseCode.CONTENT, tree, MediaTypeRegistry.APPLICATION_LINK_FORMAT); } else { exchange.respond(ResponseCode.BAD_OPTION, "only one search query is supported!", MediaTypeRegistry.TEXT_PLAIN); } }
@Override public void handleGET(CoapExchange exchange) { List<String> queries = exchange.getRequestOptions().getUriQuery(); String c = content; for (String q : queries) { if (QUERY_UPPER_CASE.equals(q)) { c = content.toUpperCase(); } } exchange.respond(ResponseCode.CONTENT, c); }
@Override public void handleGET(CoapExchange exchange) { List<String> queries = exchange.getRequestOptions().getUriQuery(); String c = content; for (String q:queries) { if (QUERY_UPPER_CASE.equals(q)) { c = content.toUpperCase(); } } exchange.respond(ResponseCode.CONTENT, c); }
/** * Verifies that non-ASCII characters in the URI components are * not escaped when being put to Uri options. */ @Test public void testSetUriStringDoesNotEscapeNonUsAsciiChars() { String nonUsAsciiPath = "äöüß"; // german "Umlaute String nonUsAsciiQuery = "ä=öß"; Request req = Request.newGet().setURI(String.format("coap://127.0.0.1/%s?%s", nonUsAsciiPath, nonUsAsciiQuery)); List<String> path = req.getOptions().getUriPath(); assertThat(path, is(notNullValue())); assertThat(path.get(0), is(nonUsAsciiPath)); List<String> query = req.getOptions().getUriQuery(); assertThat(query, is(notNullValue())); assertThat(query.get(0), is(nonUsAsciiQuery)); }
@Override public ObserveSpec getObserveSpec() { if (exchange.advanced().getRequest().getOptions().getURIQueryCount() == 0) { return null; } final List<String> uriQueries = exchange.advanced().getRequest().getOptions().getUriQuery(); return ObserveSpecParser.parse(uriQueries); }
@Override public ObserveSpec getObserveSpec() { if (exchange.advanced().getRequest().getOptions().getURIQueryCount() == 0) { return null; } final List<String> uriQueries = exchange.advanced().getRequest().getOptions().getUriQuery(); return ObserveSpecParser.parse(uriQueries); }
private void testFiltering(String query, String expected) { Request request = Request.newGet(); request.setURI("coap://localhost/.well-known/core?" + query); DiscoveryResource discovery = new DiscoveryResource(root); String serialized = discovery.discoverTree(root, request.getOptions().getUriQuery()); System.out.println(serialized); Assert.assertEquals(expected, serialized); }
@Test public void testDiscoveryFiltering() { final String expectedTree = "</sensors/light>;if=\"sensor\";rt=\"light-lux\""; Request request = Request.newGet(); request.setURI("coap://localhost/.well-known/core?rt=light-lux"); DiscoveryResource discovery = new DiscoveryResource(root); String serialized = discovery.discoverTree(root, request.getOptions().getUriQuery()); System.out.println(serialized); Assert.assertEquals(expectedTree, serialized); }