本文整理汇总了Java中org.eclipse.californium.core.CoapResponse.isSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java CoapResponse.isSuccess方法的具体用法?Java CoapResponse.isSuccess怎么用?Java CoapResponse.isSuccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.californium.core.CoapResponse
的用法示例。
在下文中一共展示了CoapResponse.isSuccess方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import org.eclipse.californium.core.CoapResponse; //导入方法依赖的package包/类
private void set(String uriString, String payload) {
//System.out.println("payload\n" + payload);
try {
URI uri = new URI(uriString);
CoapClient client = new CoapClient(uri);
client.setEndpoint(endPoint);
CoapResponse response = client.put(payload, MediaTypeRegistry.TEXT_PLAIN);
if (response != null && response.isSuccess()) {
//System.out.println("Yay");
} else {
System.out.println("Sending payload to " + uriString + " failed!");
}
client.shutdown();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例2: set
import org.eclipse.californium.core.CoapResponse; //导入方法依赖的package包/类
protected void set(String path, String payload) {
Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "SET: " + "coaps://" + gateway_ip + "/" + path + " = " + payload);
CoapClient client = new CoapClient("coaps://" + gateway_ip + "/" + path);
client.setEndpoint(coap);
CoapResponse response = client.put(payload, MediaTypeRegistry.TEXT_PLAIN);
if (response != null && response.isSuccess()) {
//System.out.println("Yay");
} else {
logger.log(Level.SEVERE, "Sending payload to " + "coaps://" + gateway_ip + "/" + path + " failed!");
}
client.shutdown();
}
示例3: CoapResponseJson
import org.eclipse.californium.core.CoapResponse; //导入方法依赖的package包/类
public CoapResponseJson(CoapResponse coapResponse) {
if (coapResponse == null) {
status = "TIMEOUT";
payload = "";
success = false;
} else {
status = coapResponse.getCode().name();
payload = coapResponse.getResponseText();
success = coapResponse.isSuccess();
}
}
示例4: set
import org.eclipse.californium.core.CoapResponse; //导入方法依赖的package包/类
protected void set(final String path, final String payload) {
Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO,
"SET: " + "coaps://" + gateway_ip + "/" + path + " = " + payload);
final CoapClient client = new CoapClient("coaps://" + gateway_ip + "/" + path);
client.setEndpoint(coap);
final CoapResponse response = client.put(payload, MediaTypeRegistry.TEXT_PLAIN);
if ((response != null) && response.isSuccess()) {
// System.out.println("Yay");
} else {
logger.log(Level.SEVERE, "Sending payload to " + "coaps://" + gateway_ip + "/" + path + " failed!");
}
client.shutdown();
}
示例5: write
import org.eclipse.californium.core.CoapResponse; //导入方法依赖的package包/类
@Override
public void write(Batch batch) throws StageException {
Iterator<Record> records = batch.getRecords();
while (records.hasNext()) {
Record record = records.next();
CoapResponse response = null;
HttpMethod method = conf.coapMethod;
int contentType = getContentType();
try {
if (method == HttpMethod.POST || method == HttpMethod.PUT) {
ByteArrayOutputStream byteBufferOutputStream = new ByteArrayOutputStream();
try (DataGenerator dataGenerator = generatorFactory.getGenerator(byteBufferOutputStream)) {
dataGenerator.write(record);
dataGenerator.flush();
if (conf.dataFormat == DataFormat.TEXT) {
response = coapClient.post(byteBufferOutputStream.toString(), contentType);
} else {
response = coapClient.post(byteBufferOutputStream.toByteArray(), contentType);
}
}
} else if (method == HttpMethod.GET ) {
response = coapClient.get();
} else if (method == HttpMethod.DELETE ) {
response = coapClient.delete();
}
if (response == null) {
errorRecordHandler.onError(
new OnRecordErrorException(
record,
Errors.COAP_02
)
);
} else if (!response.isSuccess()) {
errorRecordHandler.onError(
new OnRecordErrorException(
record,
Errors.COAP_00,
response.getCode(),
response.getResponseText()
)
);
}
} catch (Exception ex) {
LOG.error(Errors.COAP_01.getMessage(), ex.toString(), ex);
throw new OnRecordErrorException(record, Errors.COAP_01, ex.toString());
}
}
}