当前位置: 首页>>代码示例>>Java>>正文


Java CoapResponse.isSuccess方法代码示例

本文整理汇总了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();
	}
}
 
开发者ID:hardillb,项目名称:TRADFRI2MQTT,代码行数:19,代码来源:Main.java

示例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();
}
 
开发者ID:ffleurey,项目名称:ThingML-Tradfri,代码行数:13,代码来源:TradfriGateway.java

示例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();
	}
}
 
开发者ID:mkovatsc,项目名称:iot-semantics,代码行数:13,代码来源:CoapResource.java

示例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();
}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:14,代码来源:TradfriGateway.java

示例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());
    }
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:51,代码来源:CoapClientTarget.java


注:本文中的org.eclipse.californium.core.CoapResponse.isSuccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。