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


Java CoapExchange.getRequestPayload方法代码示例

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


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

示例1: getPayload

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
public static byte[] getPayload(CoapExchange exchange, int contentFormat) {
	logger.info("---------------------------    REQUEST    -----------------------------------------");
	logger.info("Header: " + exchange.getRequestCode() + "(T=" + exchange.advanced().getRequest().getType() + ", Code=XXX, MID=" + exchange.advanced().getRequest().getMID() + ")");
	logger.info("Options: " + exchange.advanced().getRequest().getOptions().toString());
	logger.info("Authn: " + exchange.advanced().getRequest().getSenderIdentity());
	logger.info("Token: " + exchange.advanced().getRequest().getTokenString());
	
	logger.info("Uri-Path: " + exchange.advanced().getRequest().getURI());
			
    if(contentFormat == MediaTypeRegistry.APPLICATION_JSON) {
    	logger.info("Payload:\n" + new String(exchange.getRequestPayload()) + "\n");
    }
    else if(contentFormat == MediaTypeRegistry.APPLICATION_CBOR) {
    	logger.info("Payload (Diagnostic):\n" + new String(exchange.getRequestPayload()) + "\n\n");
    }
	
	return exchange.getRequestPayload();
}
 
开发者ID:erwah,项目名称:acetest,代码行数:19,代码来源:Exchange.java

示例2: payload

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
protected InputStream payload(CoapExchange exchange) {
  return new ByteArrayInputStream(exchange.getRequestPayload());
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:4,代码来源:CoAPRESTResource.java

示例3: receiveCoapRequest

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
	public void receiveCoapRequest(CoapExchange exchange) {
		
		log.debug(">> RECVD CoAP MESSAGE:");
		log.debug("Options format=" + exchange.getRequestOptions().getContentFormat());
		
		log.debug("RequestCode=" + exchange.getRequestCode());
		log.debug("RequestPayload=" +exchange.getRequestPayload());
		log.debug("Options=" + exchange.getRequestOptions());
		log.debug("UriPath=" + exchange.getRequestOptions().getUriPathString());
		if (exchange.getRequestPayload() != null) {
			log.debug(exchange.getRequestText());
		}
		
		OneM2mRequest reqMessage = null;
		try {
			//System.out.println("[COAP DEBUG]====> exchange.getSourceAddress().getHostAddress().toString()=" + exchange.getSourceAddress().getHostAddress());
			reqMessage = CoapRequestCodec.decode(exchange);
			String clientAddress = exchange.getSourceAddress().getHostAddress();	// added in 2017-08-25
			coapMap.put(reqMessage.getRequestIdentifier(), exchange);
			log.debug(reqMessage.toString());
			
			OneM2mContext context = createContext(BINDING_TYPE.BIND_COAP);
			
			new OperationProcessor(context).processRequest(reqMessage, clientAddress);

		} catch (OneM2MException e) {
			
			OneM2mResponse resMessage = new OneM2mResponse(e.getResponseStatusCode(), reqMessage);
			resMessage.setContent(new String(e.getMessage()).getBytes());
			sendCoapResponse(resMessage, exchange);
			
		} catch (Throwable th) {
			th.printStackTrace();
			log.error("COAP] RequestMessage decode failed.", th);
			if(reqMessage != null) {
				coapMap.remove(reqMessage.getRequestIdentifier());
			}
			
//			sendError(ctx);
		}
		
		
	}
 
开发者ID:iotoasis,项目名称:SI,代码行数:45,代码来源:InCse.java

示例4: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePOST(CoapExchange exchange) {
    
        Response response = new Response(CoAP.ResponseCode.CONTENT);
        
        int contentType = exchange.getRequestOptions().getContentFormat();
        int acceptTypeVal = exchange.getRequestOptions().getAccept();
        String acceptType = "";
        switch (acceptTypeVal){
        
            case MediaTypeRegistry.APPLICATION_EXI:
                break;
            case MediaTypeRegistry.APPLICATION_XML:
                acceptType= MediaType.APPLICATION_XML.getSubType();
                break;
            case MediaTypeRegistry.APPLICATION_JSON:
                acceptType= MediaType.APPLICATION_JSON.getSubType();
                break;
        }
        
        Resource01_ContextRegistration rc = new Resource01_ContextRegistration();
        byte[] message = exchange.getRequestPayload();
        InputStream isMsg =  new ByteArrayInputStream(message);
        StringRepresentation sr = new StringRepresentation("");
        
        try {
        switch (contentType){               
            
            case MediaTypeRegistry.APPLICATION_JSON:
                sr = rc.registerJsonHandler(isMsg, acceptType);
                response.setPayload(sr.getText());
                break;
            default: 
                response.setPayload("accept types supported: application/exi; application/xml; application/json");
        }            
       
    } catch (ResourceException ex) {
        Logger.getLogger(CoapR01_ContextRegistration.class.getName()).log(Level.SEVERE, null, ex);
    }
        
   exchange.respond(response);

}
 
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:44,代码来源:CoapR01_ContextRegistration.java

示例5: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePOST(CoapExchange exchange) {
    
        Response response = new Response(CoAP.ResponseCode.CONTENT);
        
        int contentType = exchange.getRequestOptions().getContentFormat();
        int acceptTypeVal = exchange.getRequestOptions().getAccept();
        String acceptType = "";
        switch (acceptTypeVal){
        
            case MediaTypeRegistry.APPLICATION_EXI:
                break;
            case MediaTypeRegistry.APPLICATION_XML:
                acceptType= MediaType.APPLICATION_XML.getSubType();
                break;
            case MediaTypeRegistry.APPLICATION_JSON:
                acceptType= MediaType.APPLICATION_JSON.getSubType();
                break;
        }
        
        Resource05_AvailabilitySubscriptionDeletion rc = new Resource05_AvailabilitySubscriptionDeletion();
        byte[] message = exchange.getRequestPayload();
        InputStream isMsg =  new ByteArrayInputStream(message);
        StringRepresentation sr = new StringRepresentation("");
        
        try {
        switch (contentType){                
                        
            case MediaTypeRegistry.APPLICATION_JSON:
                sr = rc.unsubscribeJsonHandler(isMsg, acceptType);
                response.setPayload(sr.getText());
                break;
            default:
                response.setPayload("accept types supported: application/json");
        }            
       
    } catch (ResourceException ex) {
        Logger.getLogger(CoapR05_AvailabilitySubscriptionDeletion.class.getName()).log(Level.SEVERE, null, ex);
    }
        
   exchange.respond(response);

}
 
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:44,代码来源:CoapR05_AvailabilitySubscriptionDeletion.java

示例6: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
    public void handlePOST(CoapExchange exchange) {
        
            Response response = new Response(CoAP.ResponseCode.CONTENT);
            
            int contentType = exchange.getRequestOptions().getContentFormat();
            int acceptTypeVal = exchange.getRequestOptions().getAccept();
            String acceptType = "";
            switch (acceptTypeVal){
            
                case MediaTypeRegistry.APPLICATION_EXI:
                    break;
                case MediaTypeRegistry.APPLICATION_XML:
                    acceptType= MediaType.APPLICATION_XML.getSubType();
                    break;
                case MediaTypeRegistry.APPLICATION_JSON:
                    acceptType= MediaType.APPLICATION_JSON.getSubType();
                    break;
            }
            
            Resource03_AvailabilitySubscription rc = new Resource03_AvailabilitySubscription();
            byte[] message = exchange.getRequestPayload();
            InputStream isMsg =  new ByteArrayInputStream(message);
            StringRepresentation sr = new StringRepresentation("");
            
            try {
            switch (contentType){
                
                case MediaTypeRegistry.APPLICATION_EXI:
//              decode first! TODO
//                 sr = rc.registerXmlHandler(isMsg, acceptType);
//                 byte[] exiMessage = codeSchemaLess(message);
//                 response.setPayload(exiMessage);
                   break;                
                case MediaTypeRegistry.APPLICATION_JSON:
                    sr = rc.subscribeJsonHandler(isMsg, acceptType);
                    response.setPayload(sr.getText());
                    break;
                default: 
                    response.setPayload("accept types supported: application/exi; application/xml; application/json");
            }            
           
        } catch (ResourceException ex) {
            Logger.getLogger(CoapR03_AvailabilitySubscription.class.getName()).log(Level.SEVERE, null, ex);
        }
            
       exchange.respond(response);

    }
 
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:50,代码来源:CoapR03_AvailabilitySubscription.java

示例7: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
    public void handlePOST(CoapExchange exchange) {
        
            Response response = new Response(CoAP.ResponseCode.CONTENT);
            
            int contentType = exchange.getRequestOptions().getContentFormat();
            int acceptTypeVal = exchange.getRequestOptions().getAccept();
            String acceptType = "";
            switch (acceptTypeVal){
            
                case MediaTypeRegistry.APPLICATION_EXI:
                    break;
                case MediaTypeRegistry.APPLICATION_XML:
                    acceptType= MediaType.APPLICATION_XML.getSubType();
                    break;
                case MediaTypeRegistry.APPLICATION_JSON:
                    acceptType= MediaType.APPLICATION_JSON.getSubType();
                    break;
            }
            
            Resource02_Discovery rd = new Resource02_Discovery();
            byte[] message = exchange.getRequestPayload();
            InputStream isMsg =  new ByteArrayInputStream(message);
            StringRepresentation sr = new StringRepresentation("");
            
            try {
            switch (contentType){
                
                case MediaTypeRegistry.APPLICATION_EXI:
//              decode first! TODO
//                 sr = rc.registerXmlHandler(isMsg, acceptType);
//                 byte[] exiMessage = codeSchemaLess(message);
//                 response.setPayload(exiMessage);
                   break;                
                case MediaTypeRegistry.APPLICATION_JSON:
                    sr = rd.discoveryJsonHandler(isMsg, acceptType);
                    response.setPayload(sr.getText());
                    break;
                default: 
                    response.setPayload("accept types supported: application/exi; application/xml; application/json");
            }            
           
        } catch (ResourceException ex) {
            Logger.getLogger(CoapR02_Discovery.class.getName()).log(Level.SEVERE, null, ex);
        }
            
       exchange.respond(response);

    }
 
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:50,代码来源:CoapR02_Discovery.java

示例8: handlePOST

import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
    public void handlePOST(CoapExchange exchange) {
        
            Response response = new Response(CoAP.ResponseCode.CONTENT);
            
            int contentType = exchange.getRequestOptions().getContentFormat();
            int acceptTypeVal = exchange.getRequestOptions().getAccept();
            String acceptType = "";
            switch (acceptTypeVal){
            
                case MediaTypeRegistry.APPLICATION_EXI:
                    break;
                case MediaTypeRegistry.APPLICATION_XML:
                    acceptType= MediaType.APPLICATION_XML.getSubType();
                    break;
                case MediaTypeRegistry.APPLICATION_JSON:
                    acceptType= MediaType.APPLICATION_JSON.getSubType();
                    break;
            }
            
            Resource04_AvailabilitySubscriptionUpdate rc = new Resource04_AvailabilitySubscriptionUpdate();
            byte[] message = exchange.getRequestPayload();
            InputStream isMsg =  new ByteArrayInputStream(message);
            StringRepresentation sr = new StringRepresentation("");
            
            try {
            switch (contentType){
                
                case MediaTypeRegistry.APPLICATION_EXI:
//              decode first! TODO
//                 sr = rc.registerXmlHandler(isMsg, acceptType);
//                 byte[] exiMessage = codeSchemaLess(message);
//                 response.setPayload(exiMessage);
                   break;
                case MediaTypeRegistry.APPLICATION_JSON:
                    sr = rc.subscribeJsonHandler(isMsg, acceptType);
                    response.setPayload(sr.getText());
                    break;
                default: 
                    response.setPayload("accept types supported: application/json");
            }            
           
        } catch (ResourceException ex) {
            Logger.getLogger(CoapR04_AvailabilitySubscriptionUpdate.class.getName()).log(Level.SEVERE, null, ex);
        }
            
       exchange.respond(response);

    }
 
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:50,代码来源:CoapR04_AvailabilitySubscriptionUpdate.java


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