/** * Gets the set of options of this response. * * @return the options */ public OptionSet getOptions() { return response.getOptions(); }
/** * Checks whether this response has either a <em>block1</em> or * <em>block2</em> option. * * @return {@code true} if this response has a block option. */ public boolean hasBlockOption() { return getOptions().hasBlock1() || getOptions().hasBlock2(); }
@Override protected boolean checkResponse(Request request, Response response) { boolean success = response.getOptions().hasBlock2(); if (!success) { System.out.println("FAIL: no Block2 option"); } else { success &= hasNonEmptyPalyoad(response); success &= hasContentType(response); } return success; } }
@Override public String toString() { String payload = getPayloadTracingString(); return String.format("%s-%-6s MID=%5d, Token=%s, OptionSet=%s, %s", getType(), getCode(), getMID(), getTokenString(), getOptions(), payload); }
@Override public void receiveResponse(Exchange exchange, Response response) { if (!response.getOptions().hasObserve() && !exchange.getCurrentRequest().isMulticast()) exchange.setComplete(); if (deliverer != null) { deliverer.deliverResponse(exchange, response); // notify request that response has arrived } else { LOGGER.severe("Top of CoAP stack has no deliverer to deliver response"); } }
public void check(Response response) { assertTrue("Has no observe option", response.getOptions().hasObserve()); storage.put(key, response.getOptions().getObserve()); } });
@Override public void handleGET(CoapExchange exchange) { String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n"; payload += getStatString(); Response response = new Response(ResponseCode.CONTENT); response.setPayload(payload); response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); exchange.respond(response); }
@Override public void handleGET(CoapExchange exchange) { String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n"; payload += getStatString(); Response response = new Response(ResponseCode.CONTENT); response.setPayload(payload); response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); exchange.respond(response); }
@Override public void check(final Response response) { assertTrue("Response has no ETag", response.getOptions().getETagCount() > 0); Object obj = storage.get(var); assertThat("Object stored under " + var + " is not an ETag", obj, is(instanceOf(byte[].class))); assertThat("Response contains wrong ETag", (byte[]) obj, is(response.getOptions().getETags().get(0))); } });
public void check(Response response) { assertTrue("Has no observe option", response.getOptions().hasObserve()); Object value = storage.get(key); if (value == null) { throw new IllegalArgumentException("Key " + key + " not found"); } int V1 = (Integer) value; int V2 = response.getOptions().getObserve(); boolean fresh = V1 < V2 && V2 - V1 < 1 << 23 || V1 > V2 && V1 - V2 > 1 << 23; assertTrue("Was not a fresh notification. Last obs=" + V1 + ", new=" + V2, fresh); } });
@Override public void check(final Response response) { assertThat("Wrong size2", response.getOptions().getSize2(), is(expectedSize)); }
@Override public void handleGET(CoapExchange exchange) { String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n"; payload += getStats(); Response response = new Response(ResponseCode.CONTENT); response.setPayload(payload); response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); exchange.respond(response); }
@Override protected boolean preDeliverResponse(Exchange exchange, Response response) { response.getOptions().addOption(new Option(200)); return false; } };
@Override public void handleGET(CoapExchange exchange) { String payload = "Available commands:\n - GET: show statistics\n - POST write stats to file\n - DELETE: reset statistics\n\n"; payload += getStats(); Response response = new Response(ResponseCode.CONTENT); response.setPayload(payload); response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); exchange.respond(response); }
private void buildResponse() { if (coapResponse == null) { lwM2mresponse = OperationResponse.failure(ResponseCode.GATEWAY_TIMEOUT, "Timed Out Waiting For Response."); } else if (ResponseCode.isSuccess(coapResponse.getCode())) { lwM2mresponse = OperationResponse .of(coapResponse, californiumClientIdentifierBuilder.getClientIdentifier()); } else { lwM2mresponse = OperationResponse.failure(coapResponse.getCode(), "Request Failed on Server " + coapResponse.getOptions()); } }
private ValueResponse buildContentResponse(final LwM2mPath path, final Response coapResponse) { final ResponseCode code = ResponseCode.CONTENT; LwM2mNode content; try { content = LwM2mNodeDecoder.decode(coapResponse.getPayload(), ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path); } catch (final InvalidValueException e) { final String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString()); throw new ResourceAccessException(code, path.toString(), msg, e); } return new ValueResponse(code, content); }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= checkDiscoveryAttributes(EXPECTED_IF, response.getPayloadString()); return success; } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= checkDiscoveryAttributes(EXPECTED_HREF, response.getPayloadString()); return success; } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= hasNonEmptyPalyoad(response); success &= checkDiscoveryAttributes(EXPECTED_SZ, response.getPayloadString()); return success; } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content format"); success &= hasNonEmptyPalyoad(response); success &= checkDiscoveryAttributes(EXPECTED_RT, response.getPayloadString()); return success; } }