• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Attribute类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getPostParameter

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的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.Attribute; //导入依赖的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: copyHttpBodyData

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的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


示例4: writeHttpData

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的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


示例5: decodePost

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的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


示例6: get

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的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


示例7: toString

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


示例8: setHttpRequest

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


示例9: parseQueryParams

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


示例10: handleUploadFile

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


示例11: domainKey

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


示例12: process

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


示例13: addBodyAttribute

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的package包/类
/**
 * Add a simple attribute in the body as Name=Value
 *
 * @param name
 *            name of the parameter
 * @param value
 *            the value of the parameter
 * @throws NullPointerException
 *             for name
 * @throws ErrorDataEncoderException
 *             if the encoding is in error or if the finalize were already done
 */
public void addBodyAttribute(String name, String value) throws ErrorDataEncoderException {
    if (name == null) {
        throw new NullPointerException("name");
    }
    String svalue = value;
    if (value == null) {
        svalue = "";
    }

    Attribute data = factory.createAttribute(request, name, svalue);
    addBodyHttpData(data);
}
 
开发者ID:desperado1992,项目名称:distributeTemplate,代码行数:25,代码来源:MyHttpPostRequestEncoder.java


示例14: addToParameters

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的package包/类
private void addToParameters(Map<String, List<String>> parameters, Attribute attribute) {
  try {
    String value = attribute.getValue();
    if (Strings.isNullOrEmpty(value)) {
      return;
    }

    String name = attribute.getName();
    List<String> params = parameters.computeIfAbsent(name, k -> new ArrayList<>());
    params.add(value);
  } catch (Exception e) {
    throw new RequestProcessingException(e.getMessage(), e);
  }
}
 
开发者ID:orctom,项目名称:laputa,代码行数:15,代码来源:LaputaRequestProcessor.java


示例15: messageReceived

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, Env env) throws Exception {
  if (env.getRequest().getMethod() == POST || env.getRequest().getMethod() == PUT || env.getRequest().getMethod() == PATCH) {
    HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(env.getRequest());

    for (InterfaceHttpData entry: decoder.getBodyHttpDatas()) {
      if (entry.getHttpDataType() == HttpDataType.Attribute) {
        Attribute attribute = (Attribute)entry;
        env.getRequest().setParam((String)attribute.getName(), (String)attribute.getValue());
      }
    }
  }

  nextHandler(ctx, env);
}
 
开发者ID:spinscale,项目名称:katamari,代码行数:16,代码来源:BodyDecoder.java


示例16: parse

import io.netty.handler.codec.http.multipart.Attribute; //导入依赖的package包/类
@Override
public void parse() throws Exception {
  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) {
        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));
            }
          } else if (CommonEpConstans.NEXT_PROTOCOL_ATTR_NAME.equals(data.getName())) {
            nextProtocol = ByteBuffer.wrap(attribute.get()).getInt();
            LOG.trace("[{}] next protocol is {}", getSessionUuid(), nextProtocol);
          }
        }
      }
    } else {
      LOG.error("Multipart.. size 0");
      throw new BadRequestException("HTTP Request inccorect, multiprat size is 0");
    }
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:52,代码来源:AbstractHttpSyncCommand.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RealParameter类代码示例发布时间:2022-05-21
下一篇:
Java IsoFile类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap