use of com.ociweb.gl.api.HTTPResponseService in project FogLight-Examples by oci-pronghorn.
the class IoTApp method configureWebBasedColorChange.
private void configureWebBasedColorChange(FogRuntime runtime) {
final FogCommandChannel channel = runtime.newCommandChannel(FogRuntime.PIN_WRITER | FogRuntime.I2C_WRITER);
HTTPResponseService responseService = channel.newHTTPResponseService();
runtime.addRestListener((reader) -> {
if (reader.structured().isEqual(COLOR, RED)) {
return responseService.publishHTTPResponse(reader, turnOnRed(channel) ? 200 : 500);
} else if (reader.structured().isEqual(COLOR, GREEN)) {
return responseService.publishHTTPResponse(reader, turnOnGreen(channel) ? 200 : 500);
} else if (reader.structured().isEqual(COLOR, YELLOW)) {
return responseService.publishHTTPResponse(reader, turnOnYellow(channel) ? 200 : 500);
} else {
return responseService.publishHTTPResponse(reader, 404);
}
}).includeRoutes(webRoute);
}
use of com.ociweb.gl.api.HTTPResponseService in project GreenLightning by oci-pronghorn.
the class OpenCloseTestServer method declareBehavior.
@Override
public void declareBehavior(GreenRuntime runtime) {
HTTPResponseService respClose = runtime.newCommandChannel().newHTTPResponseService();
runtime.addRestListener((r) -> {
HeaderWritable headers = (w) -> {
w.write(HTTPHeaderDefaults.CONNECTION, "close");
};
return respClose.publishHTTPResponse(r, headers, null, Writable.NO_OP);
}).includeRoutes(alwaysCloseRoute);
HTTPResponseService respOpen = runtime.newCommandChannel().newHTTPResponseService();
runtime.addRestListener((r) -> {
respOpen.publishHTTPResponse(r, 200);
return true;
}).includeRoutes(neverCloseRoute);
}
use of com.ociweb.gl.api.HTTPResponseService in project GreenLightning by oci-pronghorn.
the class AllRoutesExample2 method declareBehavior.
@Override
public void declareBehavior(GreenRuntime runtime) {
final GreenCommandChannel cmd = runtime.newCommandChannel();
final HTTPResponseService responseService = cmd.newHTTPResponseService();
RestListener listener = new RestListener() {
@Override
public boolean restRequest(HTTPRequestReader request) {
// TODO: this route is the wrong value
int id = request.getRouteId();
System.out.println(id);
return responseService.publishHTTPResponse(request, 200);
}
};
runtime.addRestListener(listener).includeAllRoutes();
}
use of com.ociweb.gl.api.HTTPResponseService in project GreenLightning by oci-pronghorn.
the class EchoExampleApp method declareBehavior.
@Override
public void declareBehavior(GreenRuntime runtime) {
HTTPResponseService resp = runtime.newCommandChannel().newHTTPResponseService();
runtime.addRestListener("restListener", (r) -> {
HeaderWritable headers = new HeaderWritable() {
@Override
public void write(HeaderWriter writer) {
writer.write(HTTPHeaderDefaults.DNT, "true");
writer.write(HTTPHeaderDefaults.STRICT_TRANSPORT_SECURITY, "hello");
}
};
Writable writable = new Writable() {
@Override
public void write(ChannelWriter writer) {
// no response
}
};
return resp.publishHTTPResponse(r, headers, null, writable);
}).includeAllRoutes();
}
Aggregations