HttpPostRequestDecoder decoder = new HttpPostRequestDecoder( new DefaultHttpDataFactory(), req); try { Function<HttpPostRequestDecoder, Boolean> hasNext = it -> { try { return it.hasNext(); } catch (HttpPostRequestDecoder.EndOfDataDecoderException ex) { return false; HttpData field = (HttpData) decoder.next(); String name = field.getName(); if (field.getHttpDataType() == HttpDataType.FileUpload) { decoder.destroy();
HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(request); List<String> valueList = new ArrayList<String>(); for (InterfaceHttpData interfaceHttpData : httpPostRequestDecoder.getBodyHttpDatas()) { if (interfaceHttpData.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { Attribute attribute = (Attribute) interfaceHttpData;
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(HTTP_DATA_FACTORY, nettyRequest); this.isMultipart = decoder.isMultipart(); decoder.offer(content); this.readHttpDataChunkByChunk(decoder); content.release();
while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data != null) { InterfaceHttpData data = decoder.currentPartialHttpData(); if (data != null) { if (partialContent == null) {
private void endDecode() { try { decoder.offer(LastHttpContent.EMPTY_LAST_CONTENT); while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data instanceof Attribute) { Attribute attr = (Attribute) data; try { attributes().add(attr.getName(), attr.getValue()); } catch (Exception e) { // Will never happen, anyway handle it somehow just in case handleException(e); } } } } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) { handleException(e); } catch (HttpPostRequestDecoder.EndOfDataDecoderException e) { // ignore this as it is expected } finally { decoder.destroy(); } }
/** * 解析请求参数 */ public static Map<String, String> parse(FullHttpRequest req) { Map<String, String> params = new HashMap<>(); // 是POST请求 HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(false), req); List<InterfaceHttpData> postList = decoder.getBodyHttpDatas(); for (InterfaceHttpData data : postList) { if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { MemoryAttribute attribute = (MemoryAttribute) data; params.put(attribute.getName(), attribute.getValue()); } } // resolve memory leak decoder.destroy(); return params; }
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(nettyRequest); decoder.offer((FullHttpRequest) nettyRequest); List<InterfaceHttpData> parmList = decoder.getBodyHttpDatas();
headers.path().toString()); req.headers().add(HttpHeaderNames.CONTENT_TYPE, contentType); postRequestDecoder = new HttpPostRequestDecoder(new NettyFileUploadDataFactory(context, this, () -> uploadHandler), req);
if (HttpPostRequestDecoder.isMultipart(req) || HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.contentEqualsIgnoreCase( contentType)) { HttpDataFactory factory = new DefaultHttpDataFactory(6553500); HttpPostRequestDecoder form = new HttpPostRequestDecoder(factory, req); try { while (form.hasNext()) { inputData.addParameter(NettyUtils.getFormData(form.next())); form.cleanFiles(); form.destroy();
public static Map<String, String> getParameters(FullHttpRequest request) { Map<String, String> paramMap = new HashMap<>(); HttpMethod method = request.method(); if (HttpMethod.GET == method) { QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); decoder.parameters().forEach((key, value) -> paramMap.put(key, value.get(0))); } else if (HttpMethod.POST == method) { HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(request); decoder.offer(request); List<InterfaceHttpData> params = decoder.getBodyHttpDatas(); for (InterfaceHttpData param : params) { Attribute data = (Attribute) param; try { paramMap.put(data.getName(), data.getValue()); } catch (IOException e) { e.printStackTrace(); } } decoder.destroy(); // } else { throw new IllegalStateException(); } return paramMap; }
decoder = new HttpPostRequestDecoder(factory, req); } catch (ErrorDataDecoderException e) { log.error("Error creating http post request decoder.", e); decoder.offer(chunk); } catch (ErrorDataDecoderException e) { log.error("Error creating http post offer.", e);
LOG.trace("CommandName: " + COMMAND_NAME + ": Parse.."); HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(factory, getRequest()); if (decoder.isMultipart()) { LOG.trace("Chunked: " + HttpHeaders.isTransferEncodingChunked(getRequest())); LOG.trace(": Multipart.."); List<InterfaceHttpData> datas = decoder.getBodyHttpDatas(); if (!datas.isEmpty()) { for (InterfaceHttpData data : datas) {
@Override protected Optional<ImmutableMap<String, String>> doExtract(final HttpRequest request) { HttpPostRequestDecoder decoder = null; try { HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); FullHttpRequest targetRequest = ((DefaultHttpRequest) request).toFullHttpRequest(); Charset charset = HttpUtil.getCharset(targetRequest); decoder = new HttpPostRequestDecoder(factory, targetRequest, charset); return of(doExtractForms(decoder)); } catch (HttpPostRequestDecoder.ErrorDataDecoderException idde) { return absent(); } catch (IOException e) { throw new MocoException(e); } finally { if (decoder != null) { decoder.destroy(); } } }
public List<InterfaceHttpData> getBodyHttpDatas() { return decoder.getBodyHttpDatas(); }
postRequestDecoder.offer(httpContent); while (postRequestDecoder.hasNext()) { InterfaceHttpData data = postRequestDecoder.next(); switch (data.getHttpDataType()) { case Attribute: InterfaceHttpData currentPartialHttpData = postRequestDecoder.currentPartialHttpData(); if (currentPartialHttpData instanceof HttpData) { messages.add(currentPartialHttpData);
@Override public void offer(HttpContent chunk) { try { decoder.offer(chunk); } catch (HttpPostRequestDecoder.ErrorDataDecoderException e1) { log.warn("Unable to decode HTTP chunk", e1); throw new WebApplicationException(HttpStatus.BAD_REQUEST.code()); } try { while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data != null) { writeHttpData(data); } } } catch (HttpPostRequestDecoder.EndOfDataDecoderException e1) { // end } }
@Override public void close() { if (decoder != null) { decoder.destroy(); } } }
public FormUrlEncodedDecoder(HttpRequest request) { this.request = request; try { decoder = new HttpPostRequestDecoder(factory, request); } catch (HttpPostRequestDecoder.ErrorDataDecoderException e1) { log.warn("Unable to decode data", e1); throw new WebApplicationException(HttpStatus.BAD_REQUEST.code()); } catch (HttpPostRequestDecoder.IncompatibleDataDecoderException e) { log.warn("Incompatible request type", e); throw new WebApplicationException(HttpStatus.BAD_REQUEST.code()); } request.setMultipart(decoder.isMultipart()); }
private void resetDecoder(HttpRequest request) { if (decoder != null) { decoder.cleanFiles(); decoder = null; } decoder = new HttpPostRequestDecoder(FACTORY, request, CharsetUtil.UTF_8); }