Java Code Examples for org.eclipse.californium.core.server.resources.CoapExchange#getRequestPayload()
The following examples show how to use
org.eclipse.californium.core.server.resources.CoapExchange#getRequestPayload() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateDriver.java From SoftwarePilot with MIT License | 6 votes |
@Override public void handlePUT(CoapExchange ce) { // Split on & and = then on ' ' String outLine = ""; byte[] payload = ce.getRequestPayload(); String inputLine = new String(payload); int AUAVsim = 0; if (inputLine.contains("dp=AUAVsim")) { AUAVsim = 1; } String[] args = inputLine.split("-");//??? if(args[0].equals("dc=help")) { ce.respond(getUsageInfo()); } else { ce.respond("Error: unknown command\n"); } }
Example 2
Source File: LocationDriver.java From SoftwarePilot with MIT License | 5 votes |
@Override public void handlePUT(CoapExchange ce) { // Split on & and = then on ' ' String outLine = ""; byte[] payload = ce.getRequestPayload(); String inputLine = new String(payload); int AUAVsim = 0; if (inputLine.contains("dp=AUAVsim")) { AUAVsim = 1; } String[] args = inputLine.split("-");//??? switch (args[0]) { case "dc=help": ce.respond(getUsageInfo()); break; case "dc=qry": String qry = args[1].substring(3); ce.respond("Location: "+queryH2(qry)); break; case "dc=tme": ce.respond("Location: time="+getStartTime()); break; case "dc=set": String Xpos = args[1].substring(3); String Ypos = args[2].substring(3); String Zpos = args[3].substring(3); addPositionH2(Xpos,Ypos,Zpos); Xcur = Xpos;Ycur=Ypos; Zcur=Zpos; ce.respond("Location: set"); break; case "dc=get": ce.respond("Location: x="+Xcur+"-y="+Ycur+"-z="+Zcur); break; default: ce.respond("Error: LocationDriver unknown command\n"); } }
Example 3
Source File: BatteryDriver.java From SoftwarePilot with MIT License | 5 votes |
@Override public void handlePUT(CoapExchange ce) { // Split on & and = then on ' ' String outLine = ""; byte[] payload = ce.getRequestPayload(); String inputLine = new String(payload); int AUAVsim = 0; if (inputLine.contains("dp=AUAVsim")) { AUAVsim = 1; } String[] args = inputLine.split("-");//??? switch (args[0]) { case "dc=help": ce.respond(getUsageInfo()); break; case "dc=qry": String qry = args[1].substring(3); ce.respond(queryH2(qry)); break; case "dc=dji": System.out.println("Battery Value is: " + djiLastReading); System.out.println("Battery MAH is: " + djiLastMAH); System.out.println("Battery Current is: "+djiCurrent); System.out.println("Battery Voltage is: "+djiVoltage); ce.respond("Percent=" + djiLastReading+", MAH="+djiLastMAH); case "dc=lcl": if (AUAVsim == 1) { lclLastReading--; addReadingH2(lclLastReading, "lcl"); ce.respond("Battery: " + Integer.toString(lclLastReading)); break; } try { Class<?> c = Class.forName("android.app.ActivityThread"); android.app.Application app = (android.app.Application) c.getDeclaredMethod("currentApplication").invoke(null); android.content.Context context = app.getApplicationContext(); BatteryManager bm = (BatteryManager)context.getSystemService("batterymanager"); int batLevel = bm.getIntProperty(4); lclLastReading = batLevel; addReadingH2(batLevel, "lcl"); ce.respond("Battery: " + Integer.toString(batLevel)); } catch (Exception e) { ce.respond("Battery: Error"); } break; case "dc=cfg": if(AUAVsim != 1){ initBatteryCallback(); } ce.respond("Battery: Configured"); default: ce.respond("Error: BatteryDriver unknown command\n"); } }
Example 4
Source File: WritableResource.java From IOT-Technical-Guide with Apache License 2.0 | 5 votes |
@Override public void handlePUT(CoapExchange exchange) { byte[] payload = exchange.getRequestPayload(); try { value = new String(payload, "UTF-8"); exchange.respond(CHANGED, value); } catch (Exception e) { e.printStackTrace(); exchange.respond(BAD_REQUEST, "Invalid String"); } }
Example 5
Source File: HelloWorld2.java From hands-on-coap with Eclipse Public License 1.0 | 5 votes |
@Override public void handlePUT(CoapExchange exchange) { byte[] payload = exchange.getRequestPayload(); try { value = new String(payload, "UTF-8"); exchange.respond(CHANGED, value); } catch (Exception e) { e.printStackTrace(); exchange.respond(BAD_REQUEST, "Invalid String"); } }
Example 6
Source File: InCse.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@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); } }
Example 7
Source File: InCse.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@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); } }