public boolean publishHTTPResponse(long connectionId, long sequenceCode, int statusCode, HTTPContentType contentType, Writable writable) { return publishHTTPResponse(connectionId, sequenceCode, statusCode, false, contentType, writable); } /**
public boolean plainRestRequest(HTTPRequestReader request) { return responseService.publishHTTPResponse(request, HTTPContentTypeDefaults.PLAIN, w -> w.write(FrameworkTest.payload) ); }
@Override public boolean restRequest(HTTPRequestReader request) { return responseService.publishHTTPResponse(request, 200, HTTPContentTypeDefaults.PLAIN, (w)-> w.append("Hello World") ); }
private boolean publishCanceledResponse() { //send the cancel response.... if (responseService.publishHTTPResponse( connectionId, sequenceCode, cancelStatusCode, false, cancelHeaderWritable, cancelType, cancelPayload)) { //keep in case we see it again. lastCancelledConnectionId = connectionId; clearAll(); return true; } else { return false; } }
public boolean publishHTTPResponse(HTTPFieldReader<?> reqeustReader, HTTPContentType contentType, Writable writable) { return publishHTTPResponse(reqeustReader.getConnectionId(), reqeustReader.getSequenceCode(), 200, false, null, contentType, writable); }
/** * * @param requestReader HTTPFieldReader arg used in publishHTTPResponse * @param statusCode int arg used in publishHTTPResponse * @return HTTPResponse with given args */ public boolean publishHTTPResponse(HTTPFieldReader<?> requestReader, int statusCode) { assert((0 != (msgCommandChannel.initFeatures & MsgCommandChannel.NET_RESPONDER))) : "CommandChannel must be created with NET_RESPONDER flag"; //logger.info("Building response for connection {} sequence {} ",w.getConnectionId(),w.getSequenceCode()); return publishHTTPResponse(requestReader.getConnectionId(), requestReader.getSequenceCode(), statusCode,false,null,Writable.NO_OP); //no type and no body so use null }
/** * * @param reqeustReader HTTPFieldReader arg used in publishHTTPResponse * @param headers HeaderWritable arg used in publishHTTPResponse * @param writable Writable arg used in publishHTTPResponse * @return publishHTTPResponse(reqeustReader.getConnectionId (), reqeustReader.getSequenceCode(), * false, headers, 200, writable) */ public boolean publishHTTPResponse(HTTPFieldReader reqeustReader, HeaderWritable headers, HTTPContentType contentType, Writable writable) { return publishHTTPResponse(reqeustReader.getConnectionId(), reqeustReader.getSequenceCode(), 200, false, headers, contentType, writable); }
/** * * @param requestReader HTTPFieldReader arg used in publishHTTPResponse * @param statusCode int used as arg in publishHTTPResponse * @param contentType HTTPContentType used as arg in publishHTTPResponse * @param writable Writable used as arg in publishHTTPResponse * @return HTTPResponse with given args */ public boolean publishHTTPResponse(HTTPFieldReader<?> requestReader, int statusCode, HTTPContentType contentType, Writable writable) { assert((0 != (msgCommandChannel.initFeatures & MsgCommandChannel.NET_RESPONDER))) : "CommandChannel must be created with NET_RESPONDER flag"; return publishHTTPResponse(requestReader.getConnectionId(), requestReader.getSequenceCode(), statusCode, false, contentType, writable); }
/** * * @param requestReader HTTPFieldReader used as arg in publishHTTPResponse * @param statusCode int used as arg in publishHTTPResponse * @param hasContinuation boolean used as arg in publishHTTPResponse * @param contentType HTTPContentType used as arg in publishHTTPResponse * @param writable Writable used as arg in publishHTTPResponse * @return HTTPResponse with given args */ public boolean publishHTTPResponse(HTTPFieldReader<?> requestReader, int statusCode, boolean hasContinuation, HTTPContentType contentType, Writable writable) { assert((0 != (msgCommandChannel.initFeatures & MsgCommandChannel.NET_RESPONDER))) : "CommandChannel must be created with NET_RESPONDER flag"; return publishHTTPResponse(requestReader.getConnectionId(), requestReader.getSequenceCode(), statusCode, hasContinuation, contentType, writable); }
private boolean publishMultiResponseDBUpdate(long conId, long seqCode) { boolean result = service.publishHTTPResponse(conId, seqCode, 200, HTTPContentTypeDefaults.JSON, w-> { Templates.multiTemplate.render(w, collectorDBUpdate); int c = collectorDBUpdate.size(); while (--c>=0) { assert(collectorDBUpdate.get(c).getConnectionId() == conId); assert(collectorDBUpdate.get(c).getSequenceId() == seqCode); collectorDBUpdate.get(c).setStatus(-1); } collectorDBUpdate.clear(); DBUpdateInFlight.publishTailPosition(); }); collectionPendingDBUpdate = !result; return result; }
@Override public boolean restRequest(HTTPRequestReader request) { StructuredReader record = request.structured(); int age = record.readInt(Field.PERSON_AGE); isLegal = age>=21; name.setLength(0); record.readText(Field.PERSON_NAME, name); return responseService.publishHTTPResponse(request, 200, HTTPContentTypeDefaults.JSON, w-> { jsonRenderer.render(w, this); }); }
public boolean productQuery(HTTPRequestReader request) { selectedId = request.structured().readInt(Field.ID); return responseService.publishHTTPResponse(request, 200, HTTPContentTypeDefaults.JSON, w-> renderSelected.render(w, this)); }
private boolean publishMultiDBResponse(long conId, long seqCode) { final boolean result = service.publishHTTPResponse(conId, seqCode, 200, HTTPContentTypeDefaults.JSON, w-> { Templates.multiTemplateDBRest.render(w, collectorDBRest); int c = collectorDBRest.size(); assert(collectorDBRest.get(0).getGroupSize()==c); while (--c >= 0) { assert(collectorDBRest.get(0).getGroupSize()==collectorDBRest.size()); assert(collectorDBRest.get(c).getConnectionId() == conId) : c+" expected conId "+conId+" error: "+showCollection(collectorDBRest); assert(collectorDBRest.get(c).getSequenceId() == seqCode) : c+" sequence error: "+showCollection(collectorDBRest); collectorDBRest.get(c).setStatus(-1); } collectorDBRest.clear(); DBRestInFlight.publishTailPosition(); }); collectionPendingDBRest = !result; return result; }
public boolean productAll(HTTPRequestReader request) { return responseService.publishHTTPResponse(request, 200, HTTPContentTypeDefaults.JSON, w-> { w.append('['); boolean isFirst = true; for(int i = 0; i<names.length; i++) { if (names[i].length()>0) { if (!isFirst) { w.append(",\n"); } isFirst=false; selectedId = i; renderSelected.render(w, this); } } w.append(']'); }); }
public boolean productUpdate(HTTPRequestReader request) { StructuredReader structured = request.structured(); int idx = structured.readInt(Field.ID); quantity[idx] = structured.readInt(Field.QUANTITY); disabled[idx] = structured.readBoolean(Field.DISABLED); names[idx].setLength(0); structured.readText(Field.NAME, names[idx] ); return responseService.publishHTTPResponse(request, 200); }
@Override public boolean message(CharSequence topic, ChannelReader payload) { StructuredReader struct = payload.structured(); return responseService.publishHTTPResponse( struct.readLong(Field.CONNECTION), struct.readLong(Field.SEQUENCE), struct.readInt(Field.STATUS), HTTPContentTypeDefaults.JSON, w->{ struct.readText(Field.PAYLOAD, w); }); }
@Override public boolean restRequest(HTTPRequestReader request) { if (request.isVerbPost()) { request.openPayloadData((reader)->{ console.append("POST: "); reader.readUTFOfLength(reader.available(),console); }); } //if this can not be published then we will get the request again later to be reattempted. return cmd.publishHTTPResponse(request, 200, false, HTTPContentTypeDefaults.TXT, (writer)-> { writer.writeUTF8Text("beginning of text file\n"); }); }
@Override public boolean restRequest(HTTPRequestReader request) { if (request.isVerbPost()) { request.openPayloadData((reader)->{ console.append("POST: "); reader.readUTFOfLength(reader.available(),console); }); } //if this can not be published then we will get the request again later to be reattempted. return cmd.publishHTTPResponse(request, 200, false, HTTPContentTypeDefaults.TXT, (writer)-> { renderer.render(writer, this); }); }
public boolean jsonRestRequest(HTTPRequestReader request) { //this check is to postpone the work if the network has become saturated if (responseService.hasRoomFor(1)) { //NOTE: this is only done here for the framework test // in a normal production deployment this JSONRender will only // be created once and held as a member. JSONRenderer<HTTPRequestReader> renderJSON = new JSONRenderer<HTTPRequestReader>() .startObject() .string(messageBytes, (o,t) -> t.write(FrameworkTest.payload) ) .endObject(); return responseService.publishHTTPResponse(request, HTTPContentTypeDefaults.JSON, w -> renderJSON.render(w,request) ); } else { return false; } }
@Override public boolean restRequest(HTTPRequestReader request) { int argInt = request.structured().readInt(nameFieldId); Appendables.appendValue(console, "Arg Int: ", argInt, "\n"); request.structured().identityVisit(HTTPHeaderDefaults.COOKIE, (id,reader,field)-> { console.append("COOKIE: "); reader.readUTF(console).append('\n'); }); if (request.isVerbPost()) { request.openPayloadData((reader)->{ console.append("POST: "); reader.readUTFOfLength(reader.available(), console); console.append('\n'); }); } //no body just a 200 ok response. return cmd.publishHTTPResponse(request, 200); }