Search in sources :

Example 1 with GreenRuntime

use of com.ociweb.gl.api.GreenRuntime 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);
}
Also used : HTTPHeaderDefaults(com.ociweb.pronghorn.network.config.HTTPHeaderDefaults) GreenRuntime(com.ociweb.gl.api.GreenRuntime) HTTPResponseService(com.ociweb.gl.api.HTTPResponseService) Writable(com.ociweb.gl.api.Writable) HeaderWritable(com.ociweb.pronghorn.network.http.HeaderWritable) GreenFramework(com.ociweb.gl.api.GreenFramework) GreenApp(com.ociweb.gl.api.GreenApp) HeaderWritable(com.ociweb.pronghorn.network.http.HeaderWritable) HTTPResponseService(com.ociweb.gl.api.HTTPResponseService)

Example 2 with GreenRuntime

use of com.ociweb.gl.api.GreenRuntime 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();
}
Also used : HTTPHeaderDefaults(com.ociweb.pronghorn.network.config.HTTPHeaderDefaults) GreenRuntime(com.ociweb.gl.api.GreenRuntime) HTTPResponseService(com.ociweb.gl.api.HTTPResponseService) Writable(com.ociweb.gl.api.Writable) HeaderWriter(com.ociweb.pronghorn.network.http.HeaderWriter) HeaderWritable(com.ociweb.pronghorn.network.http.HeaderWritable) GreenFramework(com.ociweb.gl.api.GreenFramework) ChannelWriter(com.ociweb.pronghorn.pipe.ChannelWriter) GreenApp(com.ociweb.gl.api.GreenApp) HeaderWritable(com.ociweb.pronghorn.network.http.HeaderWritable) Writable(com.ociweb.gl.api.Writable) HeaderWritable(com.ociweb.pronghorn.network.http.HeaderWritable) HeaderWriter(com.ociweb.pronghorn.network.http.HeaderWriter) HTTPResponseService(com.ociweb.gl.api.HTTPResponseService) ChannelWriter(com.ociweb.pronghorn.pipe.ChannelWriter)

Aggregations

GreenApp (com.ociweb.gl.api.GreenApp)2 GreenFramework (com.ociweb.gl.api.GreenFramework)2 GreenRuntime (com.ociweb.gl.api.GreenRuntime)2 HTTPResponseService (com.ociweb.gl.api.HTTPResponseService)2 Writable (com.ociweb.gl.api.Writable)2 HTTPHeaderDefaults (com.ociweb.pronghorn.network.config.HTTPHeaderDefaults)2 HeaderWritable (com.ociweb.pronghorn.network.http.HeaderWritable)2 HeaderWriter (com.ociweb.pronghorn.network.http.HeaderWriter)1 ChannelWriter (com.ociweb.pronghorn.pipe.ChannelWriter)1