org.eclipse.californium.core.coap.Response.setPayload()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(77)

本文整理了Java中org.eclipse.californium.core.coap.Response.setPayload方法的一些代码示例,展示了Response.setPayload的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.setPayload方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Response
类名称:Response
方法名:setPayload

Response.setPayload介绍

暂无

代码示例

代码示例来源:origin: eclipse/californium

public void set(Response response) {
    response.setPayload(payload);
  }
});

代码示例来源:origin: eclipse/californium

@Override
public void handleGET(CoapExchange exchange) {
  Response response = new Response(ResponseCode.CONTENT);
  response.setPayload(new Integer(0).toString());
  exchange.respond(response);
}

代码示例来源:origin: eclipse/californium

@Override
public void handleRequest(Exchange exchange) {
  Response response = new Response(ResponseCode.CONTENT);
  response.setPayload("hello world");
  exchange.sendResponse(response);
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * 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);
}

代码示例来源:origin: com.sitewhere/sitewhere-core

/**
 * 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);
}

代码示例来源:origin: eclipse/hono

/**
 * 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);
}

代码示例来源:origin: eclipse/californium

/**
 * Respond with the specified response code and the specified payload.
 * <ul>
 *   <li>GET: Content (2.05), Valid (2.03)</li>
 *   <li>POST: Created (2.01), Changed (2.04), Deleted (2.02) </li>
 *   <li>PUT: Created (2.01), Changed (2.04)</li>
 *   <li>DELETE: Deleted (2.02)</li>
 * </ul>
 *
 * @param code the response code
 * @param payload the payload
 */
public void respond(ResponseCode code, byte[] payload) {
  Response response = new Response(code);
  response.setPayload(payload);
  respond(response);
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Respond with the specified response code and the specified payload.
 * <ul>
 *   <li>GET: Content (2.05), Valid (2.03)</li>
 *   <li>POST: Created (2.01), Changed (2.04), Deleted (2.02) </li>
 *   <li>PUT: Created (2.01), Changed (2.04)</li>
 *   <li>DELETE: Deleted (2.02)</li>
 * </ul>
 *
 * @param code the response code
 * @param payload the payload
 */
public void respond(ResponseCode code, byte[] payload) {
  Response response = new Response(code);
  response.setPayload(payload);
  respond(response);
}

代码示例来源:origin: eclipse/californium

@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);
}

代码示例来源:origin: org.eclipse.californium/californium-proxy

@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);
}

代码示例来源:origin: eclipse/leshan

@Override
public void handleRequest(Exchange exchange) {
  try {
    super.handleRequest(exchange);
  } catch (InvalidRequestException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug(String.format("InvalidRequestException while handling request(%s) on the %s resource",
          exchange.getRequest(), getURI()), e);
    }
    Response response = new Response(ResponseCode.BAD_REQUEST);
    response.setPayload(e.getMessage());
    exchange.sendResponse(response);
  } catch (Exception e) {
    LOG.error(String.format("Exception while handling request(%s) on the %s resource", exchange.getRequest(),
        getURI()), e);
    exchange.sendResponse(new Response(ResponseCode.INTERNAL_SERVER_ERROR));
  }
}

代码示例来源:origin: eclipse/californium

@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);
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Respond with the specified response code and the specified payload.
 * <ul>
 *   <li>GET: Content (2.05), Valid (2.03)</li>
 *   <li>POST: Created (2.01), Changed (2.04), Deleted (2.02) </li>
 *   <li>PUT: Created (2.01), Changed (2.04)</li>
 *   <li>DELETE: Deleted (2.02)</li>
 * </ul>
 *
 * @param code the response code
 * @param payload the payload
 */
public void respond(ResponseCode code, String payload) {
  Response response = new Response(code);
  response.setPayload(payload);
  response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
  respond(response);
}

代码示例来源:origin: eclipse/californium

/**
 * Respond with the specified response code and the specified payload.
 * <ul>
 *   <li>GET: Content (2.05), Valid (2.03)</li>
 *   <li>POST: Created (2.01), Changed (2.04), Deleted (2.02) </li>
 *   <li>PUT: Created (2.01), Changed (2.04)</li>
 *   <li>DELETE: Deleted (2.02)</li>
 * </ul>
 *
 * @param code the response code
 * @param payload the payload
 * @param contentFormat the Content-Format of the payload
 */
public void respond(ResponseCode code, byte[] payload, int contentFormat) {
  Response response = new Response(code);
  response.setPayload(payload);
  response.getOptions().setContentFormat(contentFormat);
  respond(response);
}

代码示例来源:origin: org.eclipse.californium/californium-proxy

@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);
}

代码示例来源:origin: eclipse/leshan

@Override
public void handleRequest(Exchange exchange) {
  try {
    super.handleRequest(exchange);
  } catch (InvalidRequestException e) {
    LOG.debug("InvalidRequestException while handling request({}) on the /rd resource", exchange.getRequest(),
        e);
    Response response = new Response(ResponseCode.BAD_REQUEST);
    response.setPayload(e.getMessage());
    exchange.sendResponse(response);
  } catch (RuntimeException e) {
    LOG.error("Exception while handling request({}) on the /rd resource", exchange.getRequest(), e);
    exchange.sendResponse(new Response(ResponseCode.INTERNAL_SERVER_ERROR));
  }
}

代码示例来源:origin: eclipse/californium

@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

代码示例来源:origin: eclipse/californium

@Override
public void handleGET(CoapExchange exchange) {
  int delay = this.delay.getAndSet(0);
  if (0 < delay) {
    try {
      Thread.sleep(delay);
    } catch (InterruptedException e) {
    }
  }
  if (reject.compareAndSet(true, false)) {
    exchange.reject();
  } else {
    Response response = new Response(ResponseCode.CONTENT);
    response.setPayload(currentResponse);
    response.setType(type);
    exchange.respond(response);
  }
}

代码示例来源:origin: eclipse/californium

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);
}

代码示例来源:origin: eclipse/californium

@Test public void testUTF8Encoding() {
    Response response = new Response(ResponseCode.CONTENT);
    response.setType(Type.NON);
    response.setMID(expectedMid);
    response.setToken(new byte[] {});
    response.getOptions().addLocationPath("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ").addLocationPath("γλώσσα")
        .addLocationPath("пустынных").addLocationQuery("ვეპხის=யாமறிந்த").addLocationQuery("⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎");
    response.setPayload("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑");

    RawData rawData = serializer.serializeResponse(response);

    Response result = (Response) parser.parseMessage(rawData);
    assertEquals("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ/γλώσσα/пустынных", response.getOptions().getLocationPathString());
    assertEquals("ვეპხის=யாமறிந்த&⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎", response.getOptions().getLocationQueryString());
    assertEquals("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑", result.getPayloadString());
    assertEquals(response.getMID(), result.getMID());
  }
}

相关文章