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


Java CoapExchange.respond方法代码示例

本文整理汇总了Java中org.eclipse.californium.core.server.resources.CoapExchange.respond方法的典型用法代码示例。如果您正苦于以下问题:Java CoapExchange.respond方法的具体用法?Java CoapExchange.respond怎么用?Java CoapExchange.respond使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.californium.core.server.resources.CoapExchange的用法示例。


在下文中一共展示了CoapExchange.respond方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePOST(CoapExchange exchange) {
  Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
  if (!featureType.isPresent()) {
    log.trace("Missing feature type parameter");
    exchange.respond(ResponseCode.BAD_REQUEST);
  } else {
    switch (featureType.get()) {
    case ATTRIBUTES:
      processRequest(exchange, MsgType.POST_ATTRIBUTES_REQUEST);
      break;
    case TELEMETRY:
      processRequest(exchange, MsgType.POST_TELEMETRY_REQUEST);
      break;
    case RPC:
      Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest());
      if (requestId.isPresent()) {
        processRequest(exchange, MsgType.TO_DEVICE_RPC_RESPONSE);
      } else {
        processRequest(exchange, MsgType.TO_SERVER_RPC_REQUEST);
      }
      break;
    }
  }
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:26,代码来源:CoapTransportResource.java

示例2: handleGET

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
    Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
    if (!featureType.isPresent()) {
        log.trace("Missing feature type parameter");
        exchange.respond(ResponseCode.BAD_REQUEST);
    } else if (featureType.get() == FeatureType.TELEMETRY) {
        log.trace("Can't fetch/subscribe to timeseries updates");
        exchange.respond(ResponseCode.BAD_REQUEST);
    } else if (exchange.getRequestOptions().hasObserve()) {
        processExchangeGetRequest(exchange, featureType.get());
    } else if (featureType.get() == FeatureType.ATTRIBUTES) {
        processRequest(exchange, MsgType.GET_ATTRIBUTES_REQUEST);
    } else {
        log.trace("Invalid feature type parameter");
        exchange.respond(ResponseCode.BAD_REQUEST);
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:19,代码来源:CoapTransportResource.java

示例3: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePOST(CoapExchange exchange) {
    Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
    if (!featureType.isPresent()) {
        log.trace("Missing feature type parameter");
        exchange.respond(ResponseCode.BAD_REQUEST);
    } else {
        switch (featureType.get()) {
            case ATTRIBUTES:
                processRequest(exchange, MsgType.POST_ATTRIBUTES_REQUEST);
                break;
            case TELEMETRY:
                processRequest(exchange, MsgType.POST_TELEMETRY_REQUEST);
                break;
            case RPC:
                Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest());
                if (requestId.isPresent()) {
                    processRequest(exchange, MsgType.TO_DEVICE_RPC_RESPONSE);
                } else {
                    processRequest(exchange, MsgType.TO_SERVER_RPC_REQUEST);
                }
                break;
        }
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:26,代码来源:CoapTransportResource.java

示例4: handle

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
public void handle(CoapExchange exchange) {
  if (shuttingDown) {
    LOG.debug("Shutting down, discarding incoming request from '{}'", exchange.getSourceAddress());
    exchange.respond(CoAP.ResponseCode.SERVICE_UNAVAILABLE);
  } else {
    long start = System.currentTimeMillis();
    LOG.debug("Request accepted from '{}'", exchange.getSourceAddress());
    try {
      if (receiver.process(exchange.getRequestPayload())) {
        exchange.respond(CoAP.ResponseCode.VALID);
        exchange.accept();
        requestMeter.mark();
      } else {
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
        exchange.accept();
        errorRequestMeter.mark();
      }
    } catch (IOException ex) {
      exchange.reject();
      errorQueue.offer(ex);
      errorRequestMeter.mark();
    } finally {
      requestTimer.update(System.currentTimeMillis() - start, TimeUnit.MILLISECONDS);
    }
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:27,代码来源:CoapReceiverResource.java

示例5: handleGET

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
  Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
  if (!featureType.isPresent()) {
    log.trace("Missing feature type parameter");
    exchange.respond(ResponseCode.BAD_REQUEST);
  } else if (featureType.get() == FeatureType.TELEMETRY) {
    log.trace("Can't fetch/subscribe to timeseries updates");
    exchange.respond(ResponseCode.BAD_REQUEST);
  } else if (exchange.getRequestOptions().hasObserve()) {
    boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1;
    MsgType msgType;
    if (featureType.get() == FeatureType.RPC) {
      msgType = unsubscribe ? MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST;
    } else {
      msgType = unsubscribe ? MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST;
    }
    Optional<SessionId> sessionId = processRequest(exchange, msgType);
    if (sessionId.isPresent()) {
      if (exchange.getRequestOptions().getObserve() == 1) {
        exchange.respond(ResponseCode.VALID);
      }
    }
  } else if (featureType.get() == FeatureType.ATTRIBUTES) {
    processRequest(exchange, MsgType.GET_ATTRIBUTES_REQUEST);
  } else {
    log.trace("Invalid feature type parameter");
    exchange.respond(ResponseCode.BAD_REQUEST);
  }
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:31,代码来源:CoapTransportResource.java

示例6: processExchangeGetRequest

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
private void processExchangeGetRequest(CoapExchange exchange, FeatureType featureType) {
    boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1;
    MsgType msgType;
    if (featureType == FeatureType.RPC) {
        msgType = unsubscribe ? MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST;
    } else {
        msgType = unsubscribe ? MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST;
    }
    Optional<SessionId> sessionId = processRequest(exchange, msgType);
    if (sessionId.isPresent()) {
        if (exchange.getRequestOptions().getObserve() == 1) {
            exchange.respond(ResponseCode.VALID);
        }
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:16,代码来源:CoapTransportResource.java

示例7: sendCoapResponse

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
private boolean sendCoapResponse(OneM2mResponse resMessage, CoapExchange exchange) {
	
	if (exchange == null) {
		return false;
	}
	
	coapMap.remove(resMessage.getRequestIdentifier());
	
	try {
		Response response = CoapResponseCodec.encode(resMessage, exchange);
		
		log.debug("<< SEND CoAP MESSAGE:");
		log.debug(response.toString());
		log.debug(response.getPayloadString());
		exchange.respond(response);
		// added in 2017-10-31 to support CSE-relative Unstructured addressing 
		System.out.println("############### uripath-size=" + exchange.getRequestOptions().getUriPath().size());
		//System.out.println("############### resMessage.getResponseStatusCode()=" + resMessage.getResponseStatusCode());
		///System.out.println("############### resourceId=" + ((Resource)resMessage.getContentObject()).getResourceID());
		
		int len = exchange.getRequestOptions().getUriPath().size();
		int resCode = resMessage.getResponseStatusCode();
		
		if(resCode == 2001 && len == 1) {
			String resourceId = ((Resource)resMessage.getContentObject()).getResourceID();
			coapServer.add(coapServer.new HCoapResource(resourceId));
		}
		//coapServer.add(resources)
		
		return true;
	} catch (Exception e) {
		
		e.printStackTrace();
		
		exchange.respond(ResponseCode.INTERNAL_SERVER_ERROR, "Respose encoding failed");
	}
	
	return false;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:40,代码来源:InCse.java

示例8: receiveRequest

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
private void receiveRequest(CoapExchange exchange) {
	if(listener != null) {
		listener.receiveCoapRequest(exchange);
	} else {
		exchange.respond(ResponseCode.INTERNAL_SERVER_ERROR, "Not found listener");
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:8,代码来源:HCoapServer.java

示例9: respond

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
public static void respond(CoapExchange exchange, ResponseCode code, byte[] payload, int contentFormat) {
	exchange.respond(code, payload, contentFormat);

	logger.info("---------------------------    RESPONSE    ----------------------------------------");
	logger.info("Header: " + code + " Content (T=" + exchange.advanced().getRequest().getType() + ", Code=" + code + ", MID=" + exchange.advanced().getRequest().getMID() + ")");
	logger.info("Options: " + exchange.advanced().getResponse().getOptions());
	logger.info("Token: " + exchange.advanced().getRequest().getTokenString());
	
    if(contentFormat == MediaTypeRegistry.APPLICATION_JSON) {
    	logger.info("Payload:\n" + new String(payload) + "\n");
    }
    else if(contentFormat == MediaTypeRegistry.APPLICATION_CBOR) {
    	logger.info("Payload (Diagnostic):\n" + new String(payload) + "\n");
    }
}
 
开发者ID:erwah,项目名称:acetest,代码行数:16,代码来源:Exchange.java

示例10: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePOST(CoapExchange exchange) {
    Request request = exchange.advanced().getRequest();

    LOG.debug("POST received : {}", request);

    // The LWM2M spec (section 8.2) mandates the usage of confirmable messages
    if (!Type.CON.equals(request.getType())) {
        exchange.respond(ResponseCode.BAD_REQUEST);
        return;
    }

    List<String> uri = exchange.getRequestOptions().getUriPath();
    if (uri == null || uri.size() == 0 || !RESOURCE_NAME.equals(uri.get(0))) {
        exchange.respond(ResponseCode.BAD_REQUEST);
        return;
    }

    if (uri.size() == 1) {
        handleRegister(exchange, request);
        return;
    } else if (uri.size() == 2) {
        handleUpdate(exchange, request, uri.get(1));
        return;
    } else {
        exchange.respond(ResponseCode.BAD_REQUEST);
        return;
    }
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:30,代码来源:RegisterResource.java

示例11: handleGET

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
	// TODO Auto-generated method stub
	Log.i("DIMXML", "Using GET");

	exchange.respond(CONTENT, bloodPressureStr, dataCf);
}
 
开发者ID:AINLAB,项目名称:OHP-M2M,代码行数:8,代码来源:Spo2DIMResource.java

示例12: handleGET

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
	// TODO Auto-generated method stub
	
	exchange.setMaxAge(5);
	exchange.respond(CONTENT, m_device_10472.m_Msg.toString(),dataCf);
}
 
开发者ID:AINLAB,项目名称:OHP-M2M,代码行数:8,代码来源:D10472PCD01Resource.java

示例13: handleDELETE

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleDELETE(CoapExchange exchange) {
    if (!StringUtils.isEmpty(exchange.getRequestOptions().getUriPathString())) {
        exchange.respond(ResponseCode.METHOD_NOT_ALLOWED);
        return;
    }

    ServerIdentity identity = ResourceUtil.extractServerIdentity(exchange, bootstrapHandler);
    BootstrapDeleteResponse response = bootstrapHandler.delete(identity, new BootstrapDeleteRequest());
    exchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:12,代码来源:RootResource.java

示例14: handlePUT

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePUT(CoapExchange exchange) {
	// TODO Auto-generated method stub
	System.out.println(this.getClass().getName() + " PUT ");
	if (!exchange.getRequestOptions().hasContentFormat()) {
		exchange.respond(BAD_REQUEST, "Content-Format not set");
		return;
	}
	// store payload
	storeDate(exchange.getRequestPayload(), exchange.getRequestOptions()
			.getContentFormat());
	exchange.respond(CHANGED);
}
 
开发者ID:AINLAB,项目名称:OHP-M2M,代码行数:14,代码来源:ObservableResource.java

示例15: handleGET

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
	// TODO Auto-generated method stub
	Log.i("DIMXML", "Using GET");
	
	exchange.respond(CONTENT, bloodPressureStr, dataCf);
}
 
开发者ID:AINLAB,项目名称:OHP-M2M,代码行数:8,代码来源:DIMXMLResource.java


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