Refine search
private void writeHttpData(InterfaceHttpData data) { try { InterfaceHttpData.HttpDataType dataType = data.getHttpDataType(); if (dataType == InterfaceHttpData.HttpDataType.Attribute) { parseAttribute((Attribute) data); } else if (dataType == InterfaceHttpData.HttpDataType.FileUpload) { parseFileUpload((FileUpload) data); } } catch (IOException e) { log.error("Parse request parameter error", e); } }
String key = currentData.getName(); buffer = wrappedBuffer(key.getBytes()); isKey = false; size -= buffer.readableBytes() + 1; if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) { buffer = fillByteBuf(); return new DefaultHttpContent(buffer); if (buffer.readableBytes() < size) { isKey = true; delimiter = iterator.hasNext() ? wrappedBuffer("&".getBytes()) : null;
/** * Destroy the {@link HttpPostMultipartRequestDecoder} and release all it resources. After this method * was called it is not possible to operate on it anymore. */ @Override public void destroy() { checkDestroyed(); cleanFiles(); destroyed = true; if (undecodedChunk != null && undecodedChunk.refCnt() > 0) { undecodedChunk.release(); undecodedChunk = null; } // release all data which was not yet pulled for (int i = bodyListHttpDataRank; i < bodyListHttpData.size(); i++) { bodyListHttpData.get(i).release(); } }
@Override public Object get(ChannelHandlerContext ctx, URIDecoder uriDecoder) { List<InterfaceHttpData> bodyHttpDatas = uriDecoder.getBodyHttpDatas(); if (bodyHttpDatas == null || bodyHttpDatas.size() == 0) { return null; } for (InterfaceHttpData data : bodyHttpDatas) { if (name.equals(data.getName())) { if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { Attribute attribute = (Attribute) data; try { return ReflectionUtil.castTo(type, attribute.getValue()); } catch (IOException e) { log.error("Error getting form params. Reason : {}", e.getMessage(), e); } } } } return null; }
if (data.getHttpDataType() == HttpDataType.FileUpload && tmpDir != null) { DiskFileUpload file = (DiskFileUpload) data; if (file.isCompleted()) { data.release(); response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());
InterfaceHttpData data = decoder.next(); while (data != null) { if (data.getHttpDataType().equals(InterfaceHttpData.HttpDataType.Attribute)) { List<String> values = attributes.get(data.getName()); if (values == null) { values = new ArrayList<>(1); attributes.put(data.getName(), values); throw uncheck(e); } else if (data.getHttpDataType().equals(InterfaceHttpData.HttpDataType.FileUpload)) { List<UploadedFile> values = files.computeIfAbsent(data.getName(), k -> new ArrayList<>(1)); try { FileUpload nettyFileUpload = (FileUpload) data; final ByteBuf byteBuf = nettyFileUpload.getByteBuf(); byteBuf.retain(); context.onClose(ro -> byteBuf.release());
/** * Destroy the {@link HttpPostMultipartRequestDecoder} and release all it * resources. After this method was called it is not possible to operate on it * anymore. */ @Override public void destroy() { checkDestroyed(); cleanFiles(); destroyed = true; if (undecodedChunk != null && undecodedChunk.refCnt() > 0) { undecodedChunk.release(); undecodedChunk = null; } // release all data which was not yet pulled for (int i = bodyListHttpDataRank; i < bodyListHttpData.size(); i++) { InterfaceHttpData data = bodyListHttpData.get(i); if (data.refCnt() > 0) data.release(); } }
@SuppressWarnings("unchecked") private I decodeMultipart() { HttpPostMultipartRequestDecoder decoder = new HttpPostMultipartRequestDecoder(msg.request()); List<com.simplyti.service.api.multipart.FileUpload> files = decoder.getBodyHttpDatas().stream() .filter(data->data.getHttpDataType().equals(HttpDataType.FileUpload)) .map(FileUpload.class::cast) .map(data->new com.simplyti.service.api.multipart.FileUpload(data.content().retain(),data.getFilename())) .collect(Collectors.toList()); run(decoder::destroy); return (I) files; }
String content = ((FullHttpRequest) request).content().toString(CharsetUtil.UTF_8); JSONObject object = JSON.parseObject(content); if (object != null) { resetDecoder(request); for (InterfaceHttpData data : this.decoder.getBodyHttpDatas()) { if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { Attribute attribute = (Attribute) data; params.add(new FormParam(attribute.getName(), attribute.getValue())); if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.FileUpload) { FileUpload fileUpload = (FileUpload) data; if (fileUpload.isCompleted()) {
if (data != null) { try { logger.info("BODY FileUpload: " + data.getHttpDataType().name() + ": " + data); if (data.getHttpDataType() == HttpDataType.FileUpload) { FileUpload fileUpload = (FileUpload) data; if (fileUpload.isCompleted()) { data.release();
/** * Utility function to add a new decoded data */ protected void addHttpData(InterfaceHttpData data) { if (data == null) { return; } List<InterfaceHttpData> datas = bodyMapHttpData.get(data.getName()); if (datas == null) { datas = new ArrayList<InterfaceHttpData>(1); bodyMapHttpData.put(data.getName(), datas); } datas.add(data); bodyListHttpData.add(data); }
data.release();
if (!datas.isEmpty()) { for (InterfaceHttpData data : datas) { LOG.trace("Multipart1 name " + data.getName() + " type " + data.getHttpDataType().name()); if (data.getHttpDataType() == HttpDataType.Attribute) { Attribute attribute = (Attribute) data; if (CommonEpConstans.REQUEST_SIGNATURE_ATTR_NAME.equals(data.getName())) { requestSignature = attribute.get(); if (LOG.isTraceEnabled()) { LOG.trace("Multipart name " + data.getName() + " type " + data.getHttpDataType().name() + " Signature set. size: " + requestSignature.length); LOG.trace(MessageEncoderDecoder.bytesToHex(requestSignature)); } else if (CommonEpConstans.REQUEST_KEY_ATTR_NAME.equals(data.getName())) { requestKey = attribute.get(); if (LOG.isTraceEnabled()) { LOG.trace("Multipart name " + data.getName() + " type " + data.getHttpDataType().name() + " requestKey set. size: " + requestKey.length); LOG.trace(MessageEncoderDecoder.bytesToHex(requestKey)); } else if (CommonEpConstans.REQUEST_DATA_ATTR_NAME.equals(data.getName())) { requestData = attribute.get(); if (LOG.isTraceEnabled()) { LOG.trace("Multipart name " + data.getName() + " type " + data.getHttpDataType().name() + " requestData set. size: " + requestData.length); LOG.trace(MessageEncoderDecoder.bytesToHex(requestData));
/** * Reads request by chunk and getting values from chunk to chunk. */ private void readHttpDataChunkByChunk(HttpPostRequestDecoder decoder) { try { while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data != null) { try { // new value readAttributeOrFile(data); } finally { // Do not release the data if it's a file, we released it once everything is done. if (data.getHttpDataType() != InterfaceHttpData.HttpDataType.FileUpload) { data.release(); } } } } } catch (HttpPostRequestDecoder.EndOfDataDecoderException e) { LOGGER.debug("Error when decoding content, end of data reached", e); } }
/** * Utility function to add a new decoded data */ protected void addHttpData(InterfaceHttpData data) { if (data == null) { return; } List<InterfaceHttpData> datas = bodyMapHttpData.get(data.getName()); if (datas == null) { datas = new ArrayList<InterfaceHttpData>(1); bodyMapHttpData.put(data.getName(), datas); } datas.add(data); bodyListHttpData.add(data); }
data.release();
String key = currentData.getName(); buffer = wrappedBuffer(key.getBytes()); isKey = false; size -= buffer.readableBytes() + 1; if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) { buffer = fillByteBuf(); return new DefaultHttpContent(buffer); if (buffer.readableBytes() < size) { isKey = true; delimiter = iterator.hasNext() ? wrappedBuffer("&".getBytes()) : null;
/** * Destroy the {@link HttpPostMultipartRequestDecoder} and release all it resources. After this method * was called it is not possible to operate on it anymore. */ @Override public void destroy() { checkDestroyed(); cleanFiles(); destroyed = true; if (undecodedChunk != null && undecodedChunk.refCnt() > 0) { undecodedChunk.release(); undecodedChunk = null; } // release all data which was not yet pulled for (int i = bodyListHttpDataRank; i < bodyListHttpData.size(); i++) { bodyListHttpData.get(i).release(); } }
private void writeHttpData(InterfaceHttpData data) { try { InterfaceHttpData.HttpDataType dataType = data.getHttpDataType(); if (dataType == InterfaceHttpData.HttpDataType.Attribute) { parseAttribute((Attribute) data); } else if (dataType == InterfaceHttpData.HttpDataType.FileUpload) { parseFileUpload((FileUpload) data); } } catch (IOException e) { log.error("Parse request parameter error", e); } }
private void handleUploadFile(InterfaceHttpData data, Message uploadMessage) throws IOException{ FileForm fileForm = uploadMessage.fileForm; if(uploadMessage.fileForm == null){ uploadMessage.fileForm = fileForm = new FileForm(); } if (data.getHttpDataType() == HttpDataType.Attribute) { Attribute attribute = (Attribute) data; fileForm.attributes.put(attribute.getName(), attribute.getValue()); return; } if (data.getHttpDataType() == HttpDataType.FileUpload) { FileUpload fileUpload = (FileUpload) data; Message.FileUpload file = new Message.FileUpload(); file.fileName = fileUpload.getFilename(); file.contentType = fileUpload.getContentType(); file.data = fileUpload.get(); List<Message.FileUpload> uploads = fileForm.files.get(data.getName()); if(uploads == null){ uploads = new ArrayList<Message.FileUpload>(); fileForm.files.put(data.getName(), uploads); } uploads.add(file); } }