@Override public void handleGET(CoapExchange exchange) { Response response = new Response(ResponseCode.CONTENT); response.setPayload(new Integer(0).toString()); exchange.respond(response); }
@Override public void handleRequest(Exchange exchange) { try { super.handleRequest(exchange); } catch (Exception e) { LOG.error("Exception while handling a request on the /bs resource", e); exchange.sendResponse(new Response(ResponseCode.INTERNAL_SERVER_ERROR)); } }
@Override public void handleRequest(Exchange exchange) { try { super.handleRequest(exchange); } catch (Exception e) { LOG.error("Exception while handling a request on the /rd resource", e); // unexpected error, we should sent something like a INTERNAL_SERVER_ERROR. // but it would not be LWM2M compliant. so BAD_REQUEST for now... exchange.sendResponse(new Response(ResponseCode.BAD_REQUEST)); } }
@Override public void handleRequest(Exchange exchange) { Response response = new Response(ResponseCode.CONTENT); response.setPayload("hello world"); exchange.sendResponse(response); }
/** * Send an error response on the given exchange. * * @param code * @param message * @param exchange */ protected void createAndSendResponse(ResponseCode code, String message, Exchange exchange) { Response response = new Response(code); response.setPayload(message); exchange.sendResponse(response); }
/** * Send an error response on the given exchange. * * @param code * @param message * @param exchange */ protected void createAndSendResponse(ResponseCode code, String message, Exchange exchange) { Response response = new Response(code); response.setPayload(message); exchange.sendResponse(response); }
/** * Respond the coap exchange with the provide error cause. * * @param exchange coap exchange to be responded * @param message error message sent as payload. * @param code response code. */ public static void respond(final CoapExchange exchange, final String message, final ResponseCode code) { final Response response = new Response(code); response.setPayload(message); exchange.respond(response); }
@Override protected boolean preDeliverRequest(Exchange exchange) { Response response = new Response(ResponseCode.CREATED); exchange.setResponse(response); return true; } };
public Response parseResponse() { assert(isResponse()); Response response = new Response(ResponseCode.valueOf(code)); parseMessage(response); return response; }
@Override public void handlePOST(CoapExchange exchange) { CoapClient client = this.createClient(exchange.getRequestText()); CoapObserveRelation relation; relation = client.observe(handler); synchronized(relationStorage) { relationStorage.put(new InetSocketAddress(exchange.getSourceAddress(), exchange.getSourcePort()), relation); } Response response = new Response(ResponseCode.VALID); 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 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 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 public void deliverRequest(Exchange exchange) { System.out.println("server received request"); exchange.sendAccept(); try { Thread.sleep(500); } catch (Exception e) {} Response response = new Response(ResponseCode.CONTENT); response.setConfirmable(false); response.setPayload(SERVER_RESPONSE); exchange.sendResponse(response); } @Override
public void handleGET(CoapExchange exchange) { Response response = new Response(CONTENT); response.setType(respType); // respType is altered throughout the test cases response.setPayload(respPayload); // payload is altered throughout the test cases exchange.respond(response); }
@Override public void go() { Response response = new Response(code); if (destination != null) { response.setDestination(destination.getAddress()); response.setDestinationPort(destination.getPort()); } setProperties(response); RawData raw = serializer.serializeResponse(response); send(raw); } }
@Test public void sendResponseExpectSent() { Request request = new Request(CoAP.Code.GET); Exchange exchange = new Exchange(request, Exchange.Origin.REMOTE); Response response = new Response(CoAP.ResponseCode.CONTENT); stack.sendResponse(exchange, response); verify(outbox).sendResponse(exchange, response); } }
@Test public void sendResponseExpectSent() { Request request = new Request(CoAP.Code.GET); Exchange exchange = new Exchange(request, Exchange.Origin.REMOTE); Response response = new Response(CoAP.ResponseCode.CONTENT); stack.sendResponse(exchange, response); verify(outbox).sendResponse(exchange, response); } }
private static Response responseFor(final Request request) { Response response = new Response(ResponseCode.CONTENT); response.setMID(request.getMID()); response.setToken(request.getToken()); response.setBytes(new byte[]{}); response.setSource(request.getDestination()); response.setSourcePort(request.getDestinationPort()); response.setDestination(request.getSource()); response.setDestinationPort(request.getSourcePort()); return response; } }
private Response responseFor(final Request request) { Response response = new Response(ResponseCode.CONTENT); response.setMID(request.getMID()); response.setToken(request.getToken()); response.setBytes(new byte[]{}); response.setSource(request.getDestination()); response.setSourcePort(request.getDestinationPort()); response.setDestination(request.getSource()); response.setDestinationPort(request.getSourcePort()); return response; } }