java类io.netty.handler.codec.http.multipart.InterfaceHttpData的实例源码

HttpSessionStore.java 文件源码 项目:mqttserver 阅读 27 收藏 0 点赞 0 评论 0
public static String getPostParameter(HttpRequest req, String name) {
    HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(
            new DefaultHttpDataFactory(false), req);

    InterfaceHttpData data = decoder.getBodyHttpData(name);
    if (data.getHttpDataType() == HttpDataType.Attribute) {
        Attribute attribute = (Attribute) data;
        String value = null;
        try {
            value = attribute.getValue();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return value;
    }

    return null;
}
HttpRequest.java 文件源码 项目:kurdran 阅读 33 收藏 0 点赞 0 评论 0
private  void parsePostParam(InterfaceHttpData data) {
    try {
        switch (data.getHttpDataType()) {
            case Attribute:
                Attribute param = (Attribute) data;
                this.paramsMap.put(param.getName(), Collections.singletonList(param.getValue()));
                break;
            default:
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }finally {
        data.release();
    }
}
ApiProtocol.java 文件源码 项目:netty-restful-server 阅读 25 收藏 0 点赞 0 评论 0
/**
 * request parameters put in {@link #parameters}
 *
 * @param req
 */
private void requestParametersHandler(HttpRequest req) {
    if (req.method().equals(HttpMethod.POST)) {
        HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(req);
        try {
            List<InterfaceHttpData> postList = decoder.getBodyHttpDatas();
            for (InterfaceHttpData data : postList) {
                List<String> values = new ArrayList<String>();
                MixedAttribute value = (MixedAttribute) data;
                value.setCharset(CharsetUtil.UTF_8);
                values.add(value.getValue());
                this.parameters.put(data.getName(), values);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }
}
RequestInfoImpl.java 文件源码 项目:riposte 阅读 33 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 */
@Override
public synchronized List<InterfaceHttpData> getMultipartParts() {
    if (!isMultipartRequest() || !isCompleteRequestWithAllChunks())
        return null;

    if (multipartData == null) {
        byte[] contentBytes = getRawContentBytes();
        HttpRequest fullHttpRequestForMultipartDecoder =
            (contentBytes == null)
            ? new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri())
            : new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri(),
                                         Unpooled.wrappedBuffer(contentBytes));

        fullHttpRequestForMultipartDecoder.headers().add(getHeaders());

        multipartData = new HttpPostMultipartRequestDecoder(
            new DefaultHttpDataFactory(false), fullHttpRequestForMultipartDecoder, getContentCharset()
        );
    }

    return multipartData.getBodyHttpDatas();
}
RequestInfoImplTest.java 文件源码 项目:riposte 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void getMultipartParts_works_as_expected_with_known_valid_data() throws IOException {
    // given
    RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    Whitebox.setInternalState(requestInfo, "isMultipart", true);
    Whitebox.setInternalState(requestInfo, "contentCharset", CharsetUtil.UTF_8);
    Whitebox.setInternalState(requestInfo, "protocolVersion", HttpVersion.HTTP_1_1);
    Whitebox.setInternalState(requestInfo, "method", HttpMethod.POST);
    requestInfo.isCompleteRequestWithAllChunks = true;
    requestInfo.rawContentBytes = KNOWN_MULTIPART_DATA_BODY.getBytes(CharsetUtil.UTF_8);
    requestInfo.getHeaders().set("Content-Type", KNOWN_MULTIPART_DATA_CONTENT_TYPE_HEADER);

    // when
    List<InterfaceHttpData> result = requestInfo.getMultipartParts();

    // then
    assertThat(result, notNullValue());
    assertThat(result.size(), is(1));
    InterfaceHttpData data = result.get(0);
    assertThat(data, instanceOf(FileUpload.class));
    FileUpload fileUploadData = (FileUpload)data;
    assertThat(fileUploadData.getName(), is(KNOWN_MULTIPART_DATA_NAME));
    assertThat(fileUploadData.getFilename(), is(KNOWN_MULTIPART_DATA_FILENAME));
    assertThat(fileUploadData.getString(CharsetUtil.UTF_8), is(KNOWN_MULTIPART_DATA_ATTR_UUID));
}
RequestInfoImplTest.java 文件源码 项目:riposte 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void getMultipartParts_works_as_expected_with_known_empty_data() throws IOException {
    // given
    RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    Whitebox.setInternalState(requestInfo, "isMultipart", true);
    Whitebox.setInternalState(requestInfo, "contentCharset", CharsetUtil.UTF_8);
    Whitebox.setInternalState(requestInfo, "protocolVersion", HttpVersion.HTTP_1_1);
    Whitebox.setInternalState(requestInfo, "method", HttpMethod.POST);
    requestInfo.isCompleteRequestWithAllChunks = true;
    requestInfo.rawContentBytes = null;
    requestInfo.getHeaders().set("Content-Type", KNOWN_MULTIPART_DATA_CONTENT_TYPE_HEADER);

    // when
    List<InterfaceHttpData> result = requestInfo.getMultipartParts();

    // then
    assertThat(result, notNullValue());
    assertThat(result.isEmpty(), is(true));
}
RequestInfoImplTest.java 文件源码 项目:riposte 阅读 21 收藏 0 点赞 0 评论 0
@Test(expected = IllegalStateException.class)
public void getMultipartParts_explodes_if_multipartData_had_been_released() throws IOException {
    // given
    RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    Whitebox.setInternalState(requestInfo, "isMultipart", true);
    Whitebox.setInternalState(requestInfo, "contentCharset", CharsetUtil.UTF_8);
    Whitebox.setInternalState(requestInfo, "protocolVersion", HttpVersion.HTTP_1_1);
    Whitebox.setInternalState(requestInfo, "method", HttpMethod.POST);
    requestInfo.isCompleteRequestWithAllChunks = true;
    requestInfo.rawContentBytes = KNOWN_MULTIPART_DATA_BODY.getBytes(CharsetUtil.UTF_8);
    requestInfo.getHeaders().set("Content-Type", KNOWN_MULTIPART_DATA_CONTENT_TYPE_HEADER);
    List<InterfaceHttpData> result = requestInfo.getMultipartParts();
    assertThat(result, notNullValue());
    assertThat(result.size(), is(1));

    // expect
    requestInfo.releaseMultipartData();
    requestInfo.getMultipartParts();
    fail("Expected an error, but none was thrown");
}
RequestInfoImplTest.java 文件源码 项目:riposte 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void getMultipartParts_returns_data_from_multipartData() {
    // given
    RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    Whitebox.setInternalState(requestInfo, "isMultipart", true);
    requestInfo.isCompleteRequestWithAllChunks = true;
    HttpPostMultipartRequestDecoder multipartDataMock = mock(HttpPostMultipartRequestDecoder.class);
    List<InterfaceHttpData> dataListMock = mock(List.class);
    doReturn(dataListMock).when(multipartDataMock).getBodyHttpDatas();
    requestInfo.multipartData = multipartDataMock;

    // when
    List<InterfaceHttpData> result = requestInfo.getMultipartParts();

    // then
    assertThat(result, is(dataListMock));
}
MessageCodec.java 文件源码 项目:zbus 阅读 31 收藏 0 点赞 0 评论 0
private void handleUploadMessage(HttpMessage httpMsg, Message uploadMessage) throws IOException{
    if (httpMsg instanceof HttpContent) { 
           HttpContent chunk = (HttpContent) httpMsg;
           decoder.offer(chunk); 
           try {
               while (decoder.hasNext()) {
                   InterfaceHttpData data = decoder.next();
                   if (data != null) {
                       try { 
                        handleUploadFile(data, uploadMessage);
                       } finally {
                           data.release();
                       }
                   }
               }
           } catch (EndOfDataDecoderException e1) { 
            //ignore
           }

           if (chunk instanceof LastHttpContent) {  
            resetUpload();
           }
       }
}
ServletNettyChannelHandler.java 文件源码 项目:netty-cookbook 阅读 26 收藏 0 点赞 0 评论 0
void copyHttpBodyData(FullHttpRequest fullHttpReq, MockHttpServletRequest servletRequest){
    ByteBuf bbContent = fullHttpReq.content();  

    if(bbContent.hasArray()) {              
        servletRequest.setContent(bbContent.array());
    } else {            
        if(fullHttpReq.getMethod().equals(HttpMethod.POST)){
            HttpPostRequestDecoder decoderPostData  = new HttpPostRequestDecoder(new DefaultHttpDataFactory(false), fullHttpReq);
            String bbContentStr = bbContent.toString(Charset.forName(UTF_8));
            servletRequest.setContent(bbContentStr.getBytes());
            if( ! decoderPostData.isMultipart() ){
                List<InterfaceHttpData> postDatas = decoderPostData.getBodyHttpDatas();
                for (InterfaceHttpData postData : postDatas) {
                    if (postData.getHttpDataType() == HttpDataType.Attribute) {
                        Attribute attribute = (Attribute) postData;
                        try {                                           
                            servletRequest.addParameter(attribute.getName(),attribute.getValue());
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }   
            }
        }           
    }   
}
HttpServerChannelHandler.java 文件源码 项目:bridje-framework 阅读 32 收藏 0 点赞 0 评论 0
private void readHttpDataChunkByChunk() throws IOException
{
    while (decoder.hasNext())
    {
        InterfaceHttpData data = decoder.next();
        if (data != null)
        {
            try
            {
                // new value
                writeHttpData(data);
            }
            finally
            {
                data.release();
            }
        }
    }
}
HttpServerChannelHandler.java 文件源码 项目:bridje-framework 阅读 22 收藏 0 点赞 0 评论 0
private void writeHttpData(InterfaceHttpData data) throws IOException
{
    if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute)
    {
        Attribute attribute = (Attribute) data;
        String value = attribute.getValue();

        if (value.length() > 65535)
        {
            throw new IOException("Data too long");
        }
        req.addPostParameter(attribute.getName(), value);
    }
    else
    {
        if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.FileUpload)
        {
            FileUpload fileUpload = (FileUpload) data;
            req.addFileUpload(fileUpload);
        }
    }
}
ApiProtocol.java 文件源码 项目:netty-restful-server 阅读 31 收藏 0 点赞 0 评论 0
/**
 * request parameters put in {@link #parameters}
 *
 * @param req
 */
private void requestParametersHandler(HttpRequest req) {
    if (req.method().equals(HttpMethod.POST)) {
        HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(req);
        try {
            List<InterfaceHttpData> postList = decoder.getBodyHttpDatas();
            for (InterfaceHttpData data : postList) {
                List<String> values = new ArrayList<String>();
                MixedAttribute value = (MixedAttribute) data;
                value.setCharset(CharsetUtil.UTF_8);
                values.add(value.getValue());
                this.parameters.put(data.getName(), values);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }
}
HttpUploadServerHandler.java 文件源码 项目:netty4.0.27Learn 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Example of reading request by chunk and getting values from chunk to chunk
 */
private void readHttpDataChunkByChunk() {
    try {
        while (decoder.hasNext()) {
            InterfaceHttpData data = decoder.next();
            if (data != null) {
                try {
                    // new value
                    writeHttpData(data);
                } finally {
                    data.release();
                }
            }
        }
    } catch (EndOfDataDecoderException e1) {
        // end
        responseContent.append("\r\n\r\nEND OF CONTENT CHUNK BY CHUNK\r\n\r\n");
    }
}
LocomotiveRequestWrapper.java 文件源码 项目:locomotive 阅读 30 收藏 0 点赞 0 评论 0
private void decodePost() {
    HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(request);
    // Form Data
    List<InterfaceHttpData> bodyHttpDatas = decoder.getBodyHttpDatas();
    try {
        for (InterfaceHttpData data : bodyHttpDatas) {
            if (data.getHttpDataType().equals(HttpDataType.Attribute)) {
                Attribute attr = (MixedAttribute) data;
                params.put(data.getName(),
                        new Param(Arrays.asList(attr.getValue())));
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    decoder.destroy();
}
FormParam.java 文件源码 项目:blynk-server 阅读 20 收藏 0 点赞 0 评论 0
@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;
}
HttpUploadServerHandler.java 文件源码 项目:netty4study 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Example of reading request by chunk and getting values from chunk to chunk
 */
private void readHttpDataChunkByChunk() {
    try {
        while (decoder.hasNext()) {
            InterfaceHttpData data = decoder.next();
            if (data != null) {
                try {
                    // new value
                    writeHttpData(data);
                } finally {
                    data.release();
                }
            }
        }
    } catch (EndOfDataDecoderException e1) {
        // end
        responseContent.append("\r\n\r\nEND OF CONTENT CHUNK BY CHUNK\r\n\r\n");
    }
}
FormParams.java 文件源码 项目:titanite 阅读 25 收藏 0 点赞 0 评论 0
private String toString(InterfaceHttpData p) {
    return callUnchecked(() -> {
        if (p != null) {
            if (p instanceof FileUpload) {
                return FileUpload.class.cast(p).getFilename();
            }
            if (p instanceof Attribute) {
                return Attribute.class.cast(p).getValue();
            }
            else {
                return null;
            }
        }
        else {
            return null;
        }
    });
}
HttpUploadServerHandler.java 文件源码 项目:distributeTemplate 阅读 30 收藏 0 点赞 0 评论 0
private void readHttpDataChunkByChunk() {
    int chunk=0;
    String checksum="";
    int sum=0;
    try {
        while (decoder.hasNext()) {
            InterfaceHttpData data = decoder.next();
            if (data != null) {
                try {

                    writeHttpData(data,chunk,checksum,sum);
                } finally {
                    data.release();
                }
            }
        }
    } catch (EndOfDataDecoderException e1) {
          return;
    } 
}
NettyHttpTestIT.java 文件源码 项目:kaa 阅读 24 收藏 0 点赞 0 评论 0
public void setHttpRequest(HttpRequest request) throws BadRequestException, IOException {
  if (request == null) {
    LOG.error("HttpRequest not initialized");
    throw new BadRequestException("HttpRequest not initialized");
  }
  if (!request.getMethod().equals(HttpMethod.POST)) {
    LOG.error("Got invalid HTTP method: expecting only POST");
    throw new BadRequestException("Incorrect method "
        + request.getMethod().toString() + ", expected POST");
  }
  HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);
  HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(factory, request);
  InterfaceHttpData data = decoder.getBodyHttpData(HTTP_TEST_ATTRIBUTE);
  if (data == null) {
    LOG.error("HTTP Resolve request inccorect, {} attribute not found", HTTP_TEST_ATTRIBUTE);
    throw new BadRequestException("HTTP Resolve request inccorect, " +
        HTTP_TEST_ATTRIBUTE + " attribute not found");
  }
  Attribute attribute = (Attribute) data;
  requestData = attribute.get();
  LOG.trace("Name {}, type {} found, data size {}", data.getName(), data.getHttpDataType().name(), requestData.length);
}
HttpUploadServerHandler.java 文件源码 项目:netty-netty-5.0.0.Alpha1 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Example of reading request by chunk and getting values from chunk to chunk
 */
private void readHttpDataChunkByChunk() {
    try {
        while (decoder.hasNext()) {
            InterfaceHttpData data = decoder.next();
            if (data != null) {
                try {
                    // new value
                    writeHttpData(data);
                } finally {
                    data.release();
                }
            }
        }
    } catch (EndOfDataDecoderException e1) {
        // end
        responseContent.append("\r\n\r\nEND OF CONTENT CHUNK BY CHUNK\r\n\r\n");
    }
}
Request.java 文件源码 项目:sardine 阅读 26 收藏 0 点赞 0 评论 0
private Map<String, List<String>> parseQueryParams() {
    // query string
    final QueryStringDecoder query = new QueryStringDecoder(uri());
    final Map<String, List<String>> queryParams = new HashMap<>(query.parameters());

    //TODO multipart/form-data
    if (!"application/x-www-form-urlencoded".equalsIgnoreCase(contentType())) return queryParams;

    // http body
    final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(request);
    final List<InterfaceHttpData> bodyHttpDatas = decoder.getBodyHttpDatas();
    bodyHttpDatas.stream()
            .parallel()
            .filter(e -> e.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute)
            .map(e -> (Attribute) e)
            .map(e -> {
                try {
                    return new AbstractMap.SimpleImmutableEntry<String, String>(e.getName(), e.getValue());
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            })
            .forEach(e -> {
                String key = e.getKey();
                if (!queryParams.containsKey(key)) queryParams.putIfAbsent(key, new ArrayList<>(1));
                queryParams.get(key).add(e.getValue());
            });
    return queryParams;
}
VerifyMultipartRequestsWorkComponentTest.java 文件源码 项目:riposte 阅读 29 收藏 0 点赞 0 评论 0
@Override
public CompletableFuture<ResponseInfo<String>> execute(RequestInfo<String> request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx) {
    List<String> hashesFound = new ArrayList<>();

    for (InterfaceHttpData multipartData : request.getMultipartParts()) {
        String name = multipartData.getName();
        byte[] payloadBytes;
        try {
            payloadBytes = ((HttpData)multipartData).get();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        String filename = null;
        switch (multipartData.getHttpDataType()) {
            case Attribute:
                // Do nothing - filename stays null
                break;
            case FileUpload:
                filename = ((FileUpload)multipartData).getFilename();
                break;
            default:
                throw new RuntimeException("Unsupported multipart type: " + multipartData.getHttpDataType().name());
        }

        hashesFound.add(getHashForMultipartPayload(name, filename, payloadBytes));
    }

    return CompletableFuture.completedFuture(ResponseInfo.newBuilder(StringUtils.join(hashesFound, ",")).build());
}
RequestInfoImplTest.java 文件源码 项目:riposte 阅读 28 收藏 0 点赞 0 评论 0
@Test
public void getMultipartParts_returns_null_if_isMultipart_is_false() {
    // given
    RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    Whitebox.setInternalState(requestInfo, "isMultipart", false);
    requestInfo.isCompleteRequestWithAllChunks = true;

    // when
    List<InterfaceHttpData> result = requestInfo.getMultipartParts();

    // then
    assertThat(result, nullValue());
}
RequestInfoImplTest.java 文件源码 项目:riposte 阅读 33 收藏 0 点赞 0 评论 0
@Test
public void getMultipartParts_returns_null_if_isCompleteRequestWithAllChunks_is_false() {
    // given
    RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    Whitebox.setInternalState(requestInfo, "isMultipart", true);
    requestInfo.isCompleteRequestWithAllChunks = false;

    // when
    List<InterfaceHttpData> result = requestInfo.getMultipartParts();

    // then
    assertThat(result, nullValue());
}
HttpUploadServerHandler.java 文件源码 项目:cosmic 阅读 29 收藏 0 点赞 0 评论 0
private HttpResponseStatus readFileUploadData() throws IOException {
    while (decoder.hasNext()) {
        final InterfaceHttpData data = decoder.next();
        if (data != null) {
            try {
                logger.info("BODY FileUpload: " + data.getHttpDataType().name() + ": " + data);
                if (data.getHttpDataType() == HttpDataType.FileUpload) {
                    final FileUpload fileUpload = (FileUpload) data;
                    if (fileUpload.isCompleted()) {
                        requestProcessed = true;
                        final String format = ImageStoreUtil.checkTemplateFormat(fileUpload.getFile().getAbsolutePath(), fileUpload.getFilename());
                        if (StringUtils.isNotBlank(format)) {
                            final String errorString = "File type mismatch between the sent file and the actual content. Received: " + format;
                            logger.error(errorString);
                            responseContent.append(errorString);
                            storageResource.updateStateMapWithError(uuid, errorString);
                            return HttpResponseStatus.BAD_REQUEST;
                        }
                        final String status = storageResource.postUpload(uuid, fileUpload.getFile().getName());
                        if (status != null) {
                            responseContent.append(status);
                            storageResource.updateStateMapWithError(uuid, status);
                            return HttpResponseStatus.INTERNAL_SERVER_ERROR;
                        } else {
                            responseContent.append("upload successful.");
                            return HttpResponseStatus.OK;
                        }
                    }
                }
            } finally {
                data.release();
            }
        }
    }
    responseContent.append("received entity is not a file");
    return HttpResponseStatus.UNPROCESSABLE_ENTITY;
}
MessageCodec.java 文件源码 项目:zbus 阅读 30 收藏 0 点赞 0 评论 0
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);
    }
}
SeedHttpHandler.java 文件源码 项目:Seed 阅读 22 收藏 0 点赞 0 评论 0
private void executePostValues(SeedRequest request,HttpPostRequestDecoder decoder){
    List<InterfaceHttpData> params = decoder.getBodyHttpDatas();
    for(InterfaceHttpData data :params){
        MixedAttribute attribute = (MixedAttribute) data;
        try {
            request.setValue(new String(attribute.getName()), URLDecoder.decode(new String(attribute.content().array()),"utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
TdIT.java 文件源码 项目:digdag 阅读 26 收藏 0 点赞 0 评论 0
private String domainKey(FullHttpRequest request)
        throws IOException
{
    FullHttpRequest copy = request.copy();
    ReferenceCountUtil.releaseLater(copy);
    HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(copy);
    List<InterfaceHttpData> keyDatas = decoder.getBodyHttpDatas("domain_key");
    assertThat(keyDatas, is(not(nullValue())));
    assertThat(keyDatas.size(), is(1));
    InterfaceHttpData domainKeyData = keyDatas.get(0);
    assertThat(domainKeyData.getHttpDataType(), is(HttpDataType.Attribute));
    return ((Attribute) domainKeyData).getValue();
}
GaleRequestProcessor.java 文件源码 项目:gale 阅读 30 收藏 0 点赞 0 评论 0
public GaleRequest process(FullHttpRequest request) {
  GaleRequest result = new GaleRequest();
  result.setUri(request.getUri());
  result.setMethod(request.getMethod());
  result.setHeaders(request.headers());
  result.setVersion(request.getProtocolVersion());

  //parse query parameters
  QueryStringDecoder queryDecoder = new QueryStringDecoder(request.getUri(), CharsetUtil.UTF_8);

  result.setPath(queryDecoder.path());
  result.getParameters().putAll(queryDecoder.parameters());
  //parse body parameters
  HttpPostRequestDecoder bodyDecoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(true), request);

  List<InterfaceHttpData> datum = bodyDecoder.getBodyHttpDatas();
  if (datum != null && !datum.isEmpty()) {
    for (InterfaceHttpData data : datum) {
      String name = data.getName();
      String value = null;
      if (data.getHttpDataType().equals(HttpDataType.Attribute)) {
        //do not parse file data
        Attribute attribute = (Attribute)data;
        try {
          value = attribute.getString(CharsetUtil.UTF_8);
          result.getParameters().add(name, value);
        } catch(Exception e) {
          ELOGGER.error(this.getClass().getName(), e);
        }
      }
    }
  }
  bodyDecoder.destroy();
  return result;
}


问题


面经


文章

微信
公众号

扫码关注公众号