private void buildRequestContent(final LwM2mContentRequest request) { for (final Entry<String, String> entry : request.getClientParameters().entrySet()) { coapRequest.getOptions().addUriQuery(entry.getKey() + "=" + entry.getValue()); } final String payload = LinkFormatUtils.payloadize(clientObjectModel); coapRequest.setPayload(payload); }
public CC04(String serverURI) { super(CC04.class.getSimpleName()); // create the request Request request = Request.newPost(); // add payload request.setPayload("TD_COAP_CORE_04"); request.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); // set the parameters and execute the request executeRequest(request, serverURI, RESOURCE_URI); }
public CC19(String serverURI) { super(CC19.class.getSimpleName()); // create the request Request request = new Request(Code.POST, Type.CON); // add payload request.setPayload("TD_COAP_CORE_19"); request.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); // set the parameters and execute the request executeRequest(request, serverURI, RESOURCE_URI); }
public CB04(String serverURI) { super(CB04.class.getSimpleName()); Request request = Request.newPost(); request.setPayload(data); request.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); // set the parameters and execute the request executeRequest(request, serverURI, "/large-create"); // TODO: verify resource creation (optional): send GET request to // location path of response }
public CC03(String serverURI) { super(CC03.class.getSimpleName()); // create the request Request request = Request.newPut(); // add payload request.setPayload("TD_COAP_CORE_03"); request.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); // set the parameters and execute the request executeRequest(request, serverURI, RESOURCE_URI); }
public CC07(String serverURI) { super(CC07.class.getSimpleName()); // create the request Request request = new Request(Code.PUT); request.setConfirmable(false); // add payload request.setPayload("TD_COAP_CORE_07"); request.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); // set the parameters and execute the request executeRequest(request, serverURI, RESOURCE_URI); }
/** * Sends a PUT request with payload and required Content-Format and blocks * until the response is available. * * @param payload the payload * @param format the Content-Format * @return the CoAP response */ public CoapResponse put(byte[] payload, int format) { return synchronous(format(newPut().setURI(uri).setPayload(payload), format)); }
/** * Sends a POST request with the specified payload and the specified content * format and invokes the specified handler when a response arrives. * * @param handler the Response handler * @param payload the payload * @param format the Content-Format */ public void post(CoapHandler handler, String payload, int format) { asynchronous(format(newPost().setURI(uri).setPayload(payload), format), handler); }
/** * Sends a PUT request with payload and required Content-Format and blocks * until the response is available. * * @param payload the payload * @param format the Content-Format * @return the CoAP response */ public CoapResponse put(String payload, int format) { return synchronous(format(newPut().setURI(uri).setPayload(payload), format)); }
/** * Sends a PUT request with the specified payload and the specified content * format and invokes the specified handler when a response arrives. * * @param handler the Response handler * @param payload the payload * @param format the Content-Format */ public void put(CoapHandler handler, byte[] payload, int format) { asynchronous(format(newPut().setURI(uri).setPayload(payload), format), handler); }
/** * Sends a POST request with the specified payload and the specified content * format and invokes the specified handler when a response arrives. * * @param handler the Response handler * @param payload the payload * @param format the Content-Format */ public void post(CoapHandler handler, byte[] payload, int format) { asynchronous(format(newPost().setURI(uri).setPayload(payload), format), handler); }
public CC23(String serverURI) { super(CC23.class.getSimpleName()); Request request = new Request(Code.PUT, Type.CON); // request.setIfNoneMatch(); request.getOptions().setIfNoneMatch(true); request.setPayload("TD_COAP_CORE_23 Part A"); request.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); executeRequest(request, serverURI, RESOURCE_URI); }
/** * Sends a PUT request with the If-None-Match option set and blocks until * the response is available. * * @param payload the payload string * @param format the Content-Format * @return the CoAP response */ public CoapResponse putIfNoneMatch(String payload, int format) { return synchronous(ifNoneMatch(format(Request.newPut().setURI(uri).setPayload(payload), format))); }
/** * Sends a PUT request with with the specified ETags in the If-Match option * and blocks until the response is available. * * @param payload the payload string * @param format the Content-Format * @param etags the ETags for the If-Match option * @return the CoAP response */ public CoapResponse putIfMatch(String payload, int format, byte[] ... etags) { return synchronous(ifMatch(format(newPut().setURI(uri).setPayload(payload), format), etags)); }
/** * Sends a PUT request with the If-None-Match option set and blocks until * the response is available. * * @param payload the payload * @param format the Content-Format * @return the CoAP response */ public CoapResponse putIfNoneMatch(byte[] payload, int format) { return synchronous(ifNoneMatch(format(newPut().setURI(uri).setPayload(payload), format))); }
/** * * @param handler the Response handler * @param payload the payload * @param format the Content-Format * @param etags the ETags for the If-Match option */ public void putIfMatch(CoapHandler handler, byte[] payload, int format, byte[] ... etags) { asynchronous(ifMatch(format(newPut().setURI(uri).setPayload(payload), format), etags), handler); }
/** * * @param handler the Response handler * @param payload the payload * @param format the Content-Format */ public void putIfNoneMatch(CoapHandler handler, byte[] payload, int format) { asynchronous(ifNoneMatch(format(newPut().setURI(uri).setPayload(payload), format)), handler); }
/** * * @param handler the Response handler * @param payload the payload * @param format the Content-Format * @param etags the ETags for the If-Match option */ public void putIfMatch(CoapHandler handler, byte[] payload, int format, byte[] ... etags) { asynchronous(ifMatch(format(Request.newPut().setURI(uri).setPayload(payload), format), etags), handler); }
@Override public void visit(WriteRequest request) { coapRequest = request.isReplaceRequest() ? Request.newPut() : Request.newPost(); ContentFormat format = request.getContentFormat(); coapRequest.getOptions().setContentFormat(format.getCode()); coapRequest.setPayload(encoder.encode(request.getNode(), format, request.getPath(), model)); setTarget(coapRequest, request.getPath()); }
@Override public void visit(CreateRequest request) { coapRequest = Request.newPost(); coapRequest.getOptions().setContentFormat(request.getContentFormat().getCode()); // if no instance id, the client will assign it. int instanceId = request.getInstanceId() != null ? request.getInstanceId() : LwM2mObjectInstance.UNDEFINED; coapRequest.setPayload(encoder.encode(new LwM2mObjectInstance(instanceId, request.getResources()), request.getContentFormat(), request.getPath(), model)); setTarget(coapRequest, request.getPath()); }