/** * @param bodyPart a body part (possibly empty, but will be filtered out) */ public void accumulate(HttpResponseBodyPart bodyPart) { if (bodyPart.length() > 0) bodyParts.add(bodyPart); }
@Override public ByteBuffer getResponseBodyAsByteBuffer() { int length = 0; for (HttpResponseBodyPart part : bodyParts) length += part.length(); ByteBuffer target = ByteBuffer.wrap(new byte[length]); for (HttpResponseBodyPart part : bodyParts) target.put(part.getBodyPartBytes()); target.flip(); return target; }
@Override public State onBodyPartReceived(HttpResponseBodyPart content) throws Exception { length += content.length(); if (length > responseSizeLimit) { log.warn("Response from webhook is too big for {}. Skipping. Size : {}", email, length); return State.ABORT; } return super.onBodyPartReceived(content); }
public State onBodyPartReceived(HttpResponseBodyPart e) throws Exception { if (e.length() != 0) { String s = new String(e.getBodyPartBytes()); logger.info("got part: {}", s); queue.put(s); } return State.CONTINUE; }
/** * @param bodyPart * a body part (possibly empty, but will be filtered out) * @return this */ public ResponseBuilder accumulate(HttpResponseBodyPart bodyPart) { if (bodyPart.length() > 0) bodyParts.add(bodyPart); return this; }
@Override public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { int length = 0; for (HttpResponseBodyPart part : bodyParts) length += part.length(); ByteBuffer target = ByteBuffer.wrap(new byte[length]); for (HttpResponseBodyPart part : bodyParts) target.put(part.getBodyPartBytes()); return target; }
@Override public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { int length = 0; for (HttpResponseBodyPart part : bodyParts) length += part.length(); ByteBuffer target = ByteBuffer.wrap(new byte[length]); for (HttpResponseBodyPart part : bodyParts) target.put(part.getBodyPartBytes()); return target; }
/** * {@inheritDoc} */ public State onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { if (bytesReceived.addAndGet(content.length()) > MAX_BUFFERED_RESPONSE_SIZE) { // //trash response // for (byte b : content.getBodyPartBytes()) { // b = 0; // } // builder.accumulate(content); return State.ABORT;// TODO we might need to trash the response somehow. } builder.accumulate(content); return State.CONTINUE; }