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

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

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

Response.<init>介绍

[英]Instantiates a new response with the specified response code.
[中]用指定的响应代码实例化新响应。

代码示例

代码示例来源: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/leshan

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

代码示例来源:origin: org.eclipse.leshan/leshan-server-cf

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

代码示例来源: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

@Override
  protected boolean preDeliverRequest(Exchange exchange) {
    Response response = new Response(ResponseCode.CREATED);
    exchange.setResponse(response);
    return true;
  }
};

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

public Response parseResponse() {
  assert(isResponse());
  Response response = new Response(ResponseCode.valueOf(code));
  parseMessage(response);
  return response;
}

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

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

代码示例来源: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: 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-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/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

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

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

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

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

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

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

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

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

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

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

相关文章