/** * Gets the set of options. If no set has been defined yet, it creates a new * one. EmptyMessages should not have any options. * * @return the options */ public OptionSet getOptions() { if (options == null) options = new OptionSet(); return options; }
/** * Gets the set of options. If no set has been defined yet, it creates a new * one. EmptyMessages should not have any options. * * @return the options */ public OptionSet getOptions() { if (options == null) { options = new OptionSet(); } return options; }
/** * Sets the set of options. This function makes a defensive copy of the * specified set of options. * Provides a fluent API to chain setters. * * @param options the new options * @return this Message */ public Message setOptions(OptionSet options) { this.options = new OptionSet(options); return this; }
/** * Sets the set of options. This function makes a defensive copy of the * specified set of options. * Provides a fluent API to chain setters. * * @param options the new options * @return this Message */ public Message setOptions(OptionSet options) { this.options = new OptionSet(options); return this; }
public OdlOnem2mCoapRequestPrimitive() { optionsSet = new OptionSet(); uriQueryString = ""; }
outgoingResponse.setOptions(new OptionSet( incomingResponse.getOptions()));
outgoingResponse.setOptions(new OptionSet( incomingResponse.getOptions()));
OptionSet options = new OptionSet(incomingRequest.getOptions()); options.removeProxyUri(); options.removeBlock1();
OptionSet options = new OptionSet(incomingRequest.getOptions()); options.removeProxyUri(); options.removeProxyScheme();
private void sendCoapResponseFromOnem2mResponse(CoapExchange exchange, ResponsePrimitive onem2mResponse) { OptionSet options = new OptionSet();
private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) { int num = status.getCurrentNum(); int szx = status.getCurrentSzx(); Request block = new Request(request.getCode()); // do not enforce CON, since NON could make sense over SMS or similar transports block.setType(request.getType()); block.setDestination(request.getDestination()); block.setDestinationPort(request.getDestinationPort()); // copy options block.setOptions(new OptionSet(request.getOptions())); // copy message observers so that a failing blockwise request also notifies observers registered with // the original request block.addMessageObservers(request.getMessageObservers()); int currentSize = 1 << (4 + szx); int from = num * currentSize; int to = Math.min((num + 1) * currentSize, request.getPayloadSize()); int length = to - from; byte[] blockPayload = new byte[length]; System.arraycopy(request.getPayload(), from, blockPayload, 0, length); block.setPayload(blockPayload); boolean m = (to < request.getPayloadSize()); block.getOptions().setBlock1(szx, m, num); status.setComplete(!m); return block; }
private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) { int num = status.getCurrentNum(); int szx = status.getCurrentSzx(); Request block = new Request(request.getCode()); // do not enforce CON, since NON could make sense over SMS or similar transports block.setType(request.getType()); block.setDestination(request.getDestination()); block.setDestinationPort(request.getDestinationPort()); // copy options block.setOptions(new OptionSet(request.getOptions())); // copy message observers so that a failing blockwise request also notifies observers registered with // the original request block.addMessageObservers(request.getMessageObservers()); int currentSize = 1 << (4 + szx); int from = num * currentSize; int to = Math.min((num + 1) * currentSize, request.getPayloadSize()); int length = to - from; byte[] blockPayload = new byte[length]; System.arraycopy(request.getPayload(), from, blockPayload, 0, length); block.setPayload(blockPayload); boolean m = (to < request.getPayloadSize()); block.getOptions().setBlock1(szx, m, num); status.setComplete(!m); return block; }
private static void assembleMessage(final BlockwiseStatus status, final Message message) { // The assembled request will contain the options of the first block message.setSource(status.getFirst().getSource()); message.setSourcePort(status.getFirst().getSourcePort()); message.setType(status.getFirst().getType()); message.setMID(status.getFirst().getMID()); message.setToken(status.getFirst().getToken()); message.setOptions(new OptionSet(status.getFirst().getOptions())); int length = 0; for (byte[] block:status.getBlocks()) { length += block.length; } byte[] payload = new byte[length]; int offset = 0; for (byte[] block:status.getBlocks()) { System.arraycopy(block, 0, payload, offset, block.length); offset += block.length; } message.setPayload(payload); }
@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()); } }
private static void assembleMessage(final BlockwiseStatus status, final Message message) { // The assembled request will contain the options of the first block message.setSource(status.getFirst().getSource()); message.setSourcePort(status.getFirst().getSourcePort()); message.setType(status.getFirst().getType()); message.setMID(status.getFirst().getMID()); message.setToken(status.getFirst().getToken()); message.setOptions(new OptionSet(status.getFirst().getOptions())); message.setPayload(status.getBody()); }
block.setDestination(response.getDestination()); block.setDestinationPort(response.getDestinationPort()); block.setOptions(new OptionSet(response.getOptions()));
block.setDestination(response.getDestination()); block.setDestinationPort(response.getDestinationPort()); block.setOptions(new OptionSet(response.getOptions()));
@Test public void testUriOptions() { OptionSet options = new OptionSet(); options.setUriPath("/foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getUriPathString()); options.setUriPath("foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getUriPathString()); options.setUriPath("//foo/bar"); Assert.assertEquals("Uri-Path", "/foo/bar", options.getUriPathString()); options.setUriPath("/foo//bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getUriPathString()); options.clearUriPath(); options.addUriPath("foo"); options.addUriPath("bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getUriPathString()); options.clearUriPath(); options.addUriPath("foo"); options.addUriPath(""); options.addUriPath("bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getUriPathString()); }
@Test public void testLocationOptions() { OptionSet options = new OptionSet(); options.setLocationPath("/foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString()); options.setLocationPath("foo/bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString()); options.setLocationPath("//foo/bar"); Assert.assertEquals("Uri-Path", "/foo/bar", options.getLocationPathString()); options.setLocationPath("/foo//bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString()); options.clearLocationPath(); options.addLocationPath("foo"); options.addLocationPath("bar"); Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString()); options.clearLocationPath(); options.addLocationPath("foo"); options.addLocationPath(""); options.addLocationPath("bar"); Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString()); }
@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)); }