当前位置: 首页>>代码示例>>Java>>正文


Java InterfaceHttpData类代码示例

本文整理汇总了Java中io.netty.handler.codec.http.multipart.InterfaceHttpData的典型用法代码示例。如果您正苦于以下问题:Java InterfaceHttpData类的具体用法?Java InterfaceHttpData怎么用?Java InterfaceHttpData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InterfaceHttpData类属于io.netty.handler.codec.http.multipart包,在下文中一共展示了InterfaceHttpData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPostParameter

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
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;
}
 
开发者ID:osswangxining,项目名称:mqttserver,代码行数:19,代码来源:HttpSessionStore.java

示例2: parsePostParam

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
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();
    }
}
 
开发者ID:togethwy,项目名称:kurdran,代码行数:17,代码来源:HttpRequest.java

示例3: requestParametersHandler

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
/**
 * 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());
        }
    }
}
 
开发者ID:zhoumengkang,项目名称:netty-restful-server,代码行数:23,代码来源:ApiProtocol.java

示例4: getMultipartParts

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
/**
 * {@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();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:26,代码来源:RequestInfoImpl.java

示例5: getMultipartParts_works_as_expected_with_known_valid_data

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
@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));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:26,代码来源:RequestInfoImplTest.java

示例6: getMultipartParts_works_as_expected_with_known_empty_data

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
@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));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:20,代码来源:RequestInfoImplTest.java

示例7: getMultipartParts_explodes_if_multipartData_had_been_released

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
@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");
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:21,代码来源:RequestInfoImplTest.java

示例8: getMultipartParts_returns_data_from_multipartData

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
@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));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:18,代码来源:RequestInfoImplTest.java

示例9: handleUploadMessage

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
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();
           }
       }
}
 
开发者ID:rushmore,项目名称:zbus,代码行数:25,代码来源:MessageCodec.java

示例10: copyHttpBodyData

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
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();
						}
					}
				}	
			}
		}			
	}	
}
 
开发者ID:duchien85,项目名称:netty-cookbook,代码行数:27,代码来源:ServletNettyChannelHandler.java

示例11: readHttpDataChunkByChunk

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
private void readHttpDataChunkByChunk() throws IOException
{
    while (decoder.hasNext())
    {
        InterfaceHttpData data = decoder.next();
        if (data != null)
        {
            try
            {
                // new value
                writeHttpData(data);
            }
            finally
            {
                data.release();
            }
        }
    }
}
 
开发者ID:touwolf,项目名称:bridje-framework,代码行数:20,代码来源:HttpServerChannelHandler.java

示例12: writeHttpData

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:touwolf,项目名称:bridje-framework,代码行数:23,代码来源:HttpServerChannelHandler.java

示例13: readHttpDataChunkByChunk

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
/**
 * 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");
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:22,代码来源:HttpUploadServerHandler.java

示例14: decodePost

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
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();
}
 
开发者ID:erickzanardo,项目名称:locomotive,代码行数:18,代码来源:LocomotiveRequestWrapper.java

示例15: get

import io.netty.handler.codec.http.multipart.InterfaceHttpData; //导入依赖的package包/类
@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;
}
 
开发者ID:blynkkk,项目名称:blynk-server,代码行数:23,代码来源:FormParam.java


注:本文中的io.netty.handler.codec.http.multipart.InterfaceHttpData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。