public static DiscoverResponse internalServerError(String errorMessage) { return new DiscoverResponse(ResponseCode.INTERNAL_SERVER_ERROR, null, errorMessage); } }
public static DiscoverResponse notFound() { return new DiscoverResponse(ResponseCode.NOT_FOUND, null, null); }
public static DiscoverResponse methodNotAllowed() { return new DiscoverResponse(ResponseCode.METHOD_NOT_ALLOWED, null, null); }
public static DiscoverResponse success(Link[] links) { return new DiscoverResponse(ResponseCode.CONTENT, links, null); }
public static DiscoverResponse badRequest(String errorMessage) { return new DiscoverResponse(ResponseCode.BAD_REQUEST, null, errorMessage); }
public static DiscoverResponse unauthorized() { return new DiscoverResponse(ResponseCode.UNAUTHORIZED, null, null); }
@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); } }
@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); } }
case "discover": String objectLinks = o.getString("objectLinks", ""); return new DiscoverResponse(code, Link.parse(objectLinks.getBytes()), errorMessage); case "create": { String location = o.getString("location", null);
case "discover": String objectLinks = o.getString("objectLinks", ""); return new DiscoverResponse(code, Link.parse(objectLinks.getBytes()), errorMessage); case "create": { String location = o.getString("location", null);