private Request etags(Request request, byte[] ... etags) { for (byte[] etag : etags) { request.getOptions().addETag(etag); } return request; }
private static Request etags(final Request request, final byte[] ... etags) { for (byte[] etag : etags) { request.getOptions().addETag(etag); } return request; }
@Override public void set(final Message message) { message.getOptions().addETag(tag); } });
public void set(final Request request) { Object obj = storage.get(var); assertThat("Object stored under variable " + var + " is not a byte array", obj, is(instanceOf(byte[].class))); request.getOptions().addETag((byte[]) obj); } });
/** * Respond with the specified response. * @param response the response */ public void respond(Response response) { if (response == null) throw new NullPointerException(); // set the response options configured through the CoapExchange API if (locationPath != null) response.getOptions().setLocationPath(locationPath); if (locationQuery != null) response.getOptions().setLocationQuery(locationQuery); if (maxAge != 60) response.getOptions().setMaxAge(maxAge); if (eTag != null) { response.getOptions().clearETags(); response.getOptions().addETag(eTag); } resource.checkObserveRelation(exchange, response); exchange.sendResponse(response); }
/** * Respond with the specified response. * @param response the response */ public void respond(Response response) { if (response == null) throw new NullPointerException(); // set the response options configured through the CoapExchange API if (locationPath != null) response.getOptions().setLocationPath(locationPath); if (locationQuery != null) response.getOptions().setLocationQuery(locationQuery); if (maxAge != 60) response.getOptions().setMaxAge(maxAge); if (eTag != null) { response.getOptions().clearETags(); response.getOptions().addETag(eTag); } resource.checkObserveRelation(exchange, response); exchange.sendResponse(response); }
@Test public void testToString() { OptionSet options = new OptionSet(); options.addETag(new byte[] {1, 2, 3}); options.addETag(new byte[] {(byte)0xBE, (byte)0xEF}); options.addLocationPath("abc"); options.setUriPath("/this/is/a/test"); Assert.assertEquals("{\"ETag\":[0x010203,0xbeef], \"Location-Path\":\"abc\", \"Uri-Path\":[\"this\",\"is\",\"a\",\"test\"]}", options.toString()); options.setMaxAge(77); Assert.assertEquals("{\"ETag\":[0x010203,0xbeef], \"Location-Path\":\"abc\", \"Uri-Path\":[\"this\",\"is\",\"a\",\"test\"], \"Max-Age\":77}", options.toString()); } }
case OptionNumberRegistry.IF_MATCH: addIfMatch(option.getValue()); break; case OptionNumberRegistry.URI_HOST: setUriHost(option.getStringValue()); break; case OptionNumberRegistry.ETAG: addETag(option.getValue()); break; case OptionNumberRegistry.IF_NONE_MATCH: setIfNoneMatch(true); break; case OptionNumberRegistry.URI_PORT: setUriPort(option.getIntegerValue()); break;
case OptionNumberRegistry.IF_MATCH: addIfMatch(option.getValue()); break; case OptionNumberRegistry.URI_HOST: setUriHost(option.getStringValue()); break; case OptionNumberRegistry.ETAG: addETag(option.getValue()); break; case OptionNumberRegistry.IF_NONE_MATCH: setIfNoneMatch(true); break; case OptionNumberRegistry.URI_PORT: setUriPort(option.getIntegerValue()); break;
@Test public void testResponseParsing() { Response response = new Response(ResponseCode.CONTENT); response.setType(Type.NON); response.setMID(expectedMid); response.setToken(new byte[] { 22, -1, 0, 78, 100, 22 }); response.getOptions().addETag(new byte[] { 1, 0, 0, 0, 0, 1 }) .addLocationPath("/one/two/three/four/five/six/seven/eight/nine/ten") .addOption(new Option(57453, "Arbitrary".hashCode())).addOption(new Option(19205, "Arbitrary1")) .addOption(new Option(19205, "Arbitrary2")).addOption(new Option(19205, "Arbitrary3")); RawData rawData = serializer.serializeResponse(response); Response result = (Response) parser.parseMessage(rawData); assertEquals(response.getMID(), result.getMID()); assertArrayEquals(response.getToken(), result.getToken()); assertEquals(response.getOptions().asSortedList(), result.getOptions().asSortedList()); }
@Test public void testArbitraryOptions() { OptionSet options = new OptionSet(); options.addETag(new byte[] {1, 2, 3}); options.addLocationPath("abc"); options.addOption(new Option(7)); options.addOption(new Option(43)); options.addOption(new Option(33)); options.addOption(new Option(17)); // Check that options are in the set Assert.assertTrue(options.hasOption(OptionNumberRegistry.ETAG)); Assert.assertTrue(options.hasOption(OptionNumberRegistry.LOCATION_PATH)); Assert.assertTrue(options.hasOption(7)); Assert.assertTrue(options.hasOption(17)); Assert.assertTrue(options.hasOption(33)); Assert.assertTrue(options.hasOption(43)); // Check that others are not Assert.assertFalse(options.hasOption(19)); Assert.assertFalse(options.hasOption(53)); // Check that we can remove options options.clearETags(); Assert.assertFalse(options.hasOption(OptionNumberRegistry.ETAG)); }