/** * Gets the payload of this response as byte array. * * @return the payload */ public byte[] getPayload() { return response.getPayload(); }
/** * Checks for not empty payload. * * @param response * the response * @return true, if not empty payload */ protected boolean hasNonEmptyPalyoad(Response response) { boolean success = response.getPayload().length > 0; if (!success) { System.out.println("FAIL: Response with empty payload"); } else { System.out.printf("PASS: Payload not empty \"%s\"\n", response.getPayloadString()); } return success; }
System.arraycopy(response.getPayload(), from, blockPayload, 0, length); block.setPayload(blockPayload);
/** * Gets the payload of this response as byte array. * * @return the payload */ public byte[] getPayload() { return response.getPayload(); }
@Override public void visit(DiscoverRequest request) { if (coapResponse.isError()) { // handle error response: lwM2mresponse = new DiscoverResponse(toLwM2mResponseCode(coapResponse.getCode()), null, coapResponse.getPayloadString(), coapResponse); } else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT) { // handle success response: Link[] links; if (MediaTypeRegistry.APPLICATION_LINK_FORMAT != coapResponse.getOptions().getContentFormat()) { LOG.debug("Expected LWM2M Client [{}] to return application/link-format [{}] content but got [{}]", registration.getEndpoint(), MediaTypeRegistry.APPLICATION_LINK_FORMAT, coapResponse.getOptions().getContentFormat()); links = new Link[] {}; // empty list } else { links = Link.parse(coapResponse.getPayload()); } lwM2mresponse = new DiscoverResponse(ResponseCode.CONTENT, links, null, coapResponse); } else { // handle unexpected response: handleUnexpectedResponseCode(registration.getEndpoint(), request, coapResponse); } }
System.arraycopy(response.getPayload(), from, blockPayload, 0, length); block.setPayload(blockPayload);
@Override public byte[] getPayload() { return response.getPayload(); }
@Override public byte[] getPayload() { return response.getPayload(); }
private LwM2mNode decodeCoapResponse(LwM2mPath path, Response coapResponse, LwM2mRequest<?> request, String endpoint) { // Get content format ContentFormat contentFormat = null; if (coapResponse.getOptions().hasContentFormat()) { contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()); } // Decode payload try { return decoder.decode(coapResponse.getPayload(), contentFormat, path, model); } catch (CodecException e) { if (LOG.isDebugEnabled()) { byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload(); LOG.debug( String.format("Unable to decode response payload of request [%s] from client [%s] [payload:%s]", request, endpoint, Hex.encodeHexString(payload))); } throw new InvalidResponseException(e, "Unable to decode response payload of request [%s] from client [%s]", request, endpoint); } }
public CoapMessage(Response request, boolean incoming) { this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request .getPayload()); this.code = request.getCode().toString(); }
List<TimestampedLwM2mNode> timestampedNodes = decoder.decodeTimestampedData(coapResponse.getPayload(), contentFormat, observation.getPath(), model); byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload(); LOG.debug(String.format("Unable to decode notification payload [%s] of observation [%s] ", Hex.encodeHexString(payload), observation), e);
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); }
byte[] payload = incomingResponse.getPayload(); outgoingResponse.setPayload(payload);
byte[] payload = incomingResponse.getPayload(); outgoingResponse.setPayload(payload);
@Override public void onResponse(Response coapResponse) { if (coapResponse.getCode() == CoAP.ResponseCode.CHANGED || coapResponse.getCode() == CoAP.ResponseCode.CONTENT) { try { LwM2mNode content = LwM2mNodeDecoder.decode(coapResponse.getPayload(), ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path); ValueResponse response = new ValueResponse(ResponseCode.CHANGED, content); for (ObservationListener listener : listeners) { listener.newValue(this, response.getContent()); } } catch (InvalidValueException e) { String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString()); LOG.debug(msg); } } }
@Override public void visit(final DiscoverRequest request) { switch (coapResponse.getCode()) { case CONTENT: LinkObject[] links = null; if (MediaTypeRegistry.APPLICATION_LINK_FORMAT != coapResponse.getOptions().getContentFormat()) { LOG.debug("Expected LWM2M Client [{}] to return application/link-format [{}] content but got [{}]", client.getEndpoint(), MediaTypeRegistry.APPLICATION_LINK_FORMAT, coapResponse.getOptions() .getContentFormat()); links = new LinkObject[] {}; // empty list } else { links = LinkObject.parse(coapResponse.getPayload()); } lwM2mresponse = new DiscoverResponse(fromCoapCode(coapResponse.getCode().value), links); break; case NOT_FOUND: case UNAUTHORIZED: case METHOD_NOT_ALLOWED: lwM2mresponse = new DiscoverResponse(fromCoapCode(coapResponse.getCode().value)); break; default: handleUnexpectedResponseCode(client.getEndpoint(), coapRequest, coapResponse); } }
if (!responseStatus.addBlock(response.getPayload())) { LOGGER.log(Level.FINE, "requested resource body exceeds max buffer size [{0}], aborting request", maxResourceBodySize); exchange.getRequest().cancel();
status.addBlock(response.getPayload());