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


Java Request.setPayload方法代码示例

本文整理汇总了Java中ch.ethz.inf.vs.californium.coap.Request.setPayload方法的典型用法代码示例。如果您正苦于以下问题:Java Request.setPayload方法的具体用法?Java Request.setPayload怎么用?Java Request.setPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.ethz.inf.vs.californium.coap.Request的用法示例。


在下文中一共展示了Request.setPayload方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
public void send(byte[] data)
{
   // create new request
   Request request = new PUTRequest();
   // specify URI of target endpoint
   request.setURI(SDS_URI);
   request.setType(messageType.NON);
   request.setPayload(data);
   try
   {
      request.execute();					
   }
   catch (IOException e)
   {
      logger.error("Coap request execution failed : " + e.getMessage());
      e.printStackTrace();
   }
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:19,代码来源:DataChannelCoap.java

示例2: getHttpRequestEntityTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
@Test
public final void getHttpRequestEntityTest() throws TranslationException, IOException {
	// create the coap request
	Request coapRequest = new POSTRequest();
	coapRequest.setOption(new Option("coap://localhost:5683/resource", OptionNumberRegistry.PROXY_URI));
	coapRequest.setContentType(MediaTypeRegistry.TEXT_PLAIN);
	String payload = "aaa";
	coapRequest.setPayload(payload);

	// translate the request
	HttpRequest httpRequest = HttpTranslator.getHttpRequest(coapRequest);

	// check
	assertNotNull(httpRequest);
	assertNotNull(httpRequest.getAllHeaders());
	assertEquals(httpRequest.getClass(), BasicHttpEntityEnclosingRequest.class);

	// check the content-type
	assertEquals(httpRequest.getFirstHeader("content-type").getValue().toLowerCase(), "text/plain; charset=ISO-8859-1".toLowerCase());

	// check the content
	assertArrayEquals(payload.getBytes(), getByteArray(((HttpEntityEnclosingRequest) httpRequest).getEntity().getContent()));
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:24,代码来源:HttpTranslatorTest.java

示例3: getEntity

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
/**
 * @throws TranslationException
 * @throws IOException
 */
private void getEntity(int coapContentType, String htmlContentType) throws TranslationException, IOException {
	// create the coap message
	Request coapRequest = new POSTRequest();
	String payloadContent = "aaa";
	coapRequest.setPayload(payloadContent.getBytes());
	coapRequest.setContentType(coapContentType);

	// translate the message
	HttpEntity httpEntity = HttpTranslator.getHttpEntity(coapRequest);

	// check the existence of the http entity
	assertNotNull(httpEntity);

	// check the content-type
	assertEquals(httpEntity.getContentType().getValue(), htmlContentType);

	// check the content
	assertArrayEquals(payloadContent.getBytes(), getByteArray(httpEntity.getContent()));
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:24,代码来源:HttpTranslatorTest.java

示例4: requestTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
private void requestTest(int code, messageType type, byte[] payload, String proxyUri, List<Option> options) throws TranslationException, URISyntaxException {
	// create the test request according to the parameters
	Request incomingRequest = new Request(code, type == messageType.CON);
	incomingRequest.setPayload(payload);
	incomingRequest.setOption(new Option(proxyUri, OptionNumberRegistry.PROXY_URI));
	incomingRequest.setOptions(options);
	// set a dummy uri to emulate the proxy address
	incomingRequest.setURI(new URI("coap://localhost:666/proxy"));

	// translate the incoming request
	Request testedRequest = CoapTranslator.getRequest(incomingRequest);
	assertNotNull(testedRequest);

	// check the parameters of the message
	messageTest(incomingRequest, testedRequest);

	// check the URIs
	URI incomingRequestProxyUri = incomingRequest.getProxyUri();
	URI testedRequestCompleteUri = testedRequest.getCompleteUri();
	// check the port (default or custom)
	if (incomingRequestProxyUri.getPort() == -1) {
		// check if the absence of the port in the incoming request has been
		// translated with the default port in the translated request
		assertTrue(testedRequestCompleteUri.getPort() == COAP_DEFAULT_PORT);
	} else {
		assertTrue(incomingRequestProxyUri.equals(testedRequestCompleteUri));

		String testedRequestCompleteUriString = testedRequest.getCompleteUri().toString();
		assertTrue(proxyUri.equals(testedRequestCompleteUriString));
	}
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:32,代码来源:CoapTranslatorTest.java

示例5: getRequest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
/**
 * Starting from an external CoAP request, the method fills a new request
 * for the internal CaAP nodes. Translates the proxy-uri option in the uri
 * of the new request and simply copies the options and the payload from the
 * original request to the new one.
 * 
 * @param incomingRequest
 *            the original request
 * 
 * 
 * 
 * @return Request
 * @throws TranslationException
 *             the translation exception
 */
public static Request getRequest(final Request incomingRequest) throws TranslationException {
	// check parameters
	if (incomingRequest == null) {
		throw new IllegalArgumentException("incomingRequest == null");
	}

	// get the code
	int code = incomingRequest.getCode();

	// get message type
	messageType type = incomingRequest.getType();

	// create the request
	Request outgoingRequest = new Request(code, type == messageType.CON);

	// copy payload
	byte[] payload = incomingRequest.getPayload();
	outgoingRequest.setPayload(payload);

	// get the uri address from the proxy-uri option
	URI serverUri;
	try {
		serverUri = incomingRequest.getProxyUri();
	} catch (URISyntaxException e) {
		LOG.warning("Cannot translate the server uri" + e);
		throw new TranslationException("Cannot translate the server uri", e);
	}

	// set the proxy-uri as the outgoing uri
	if (serverUri != null) {
		outgoingRequest.setURI(serverUri);
	}

	// copy every option from the original message
	for (Option option : incomingRequest.getOptions()) {
		int optionNumber = option.getOptionNumber();

		// do not copy the proxy-uri option because it is not necessary in
		// the new message
		// do not copy the token option because it is a local option and
		// have to be assigned by the proper layer
		// do not copy the block* option because it is a local option and
		// have to be assigned by the proper layer
		// do not copy the uri-* options because they are already filled in
		// the new message
		if (optionNumber != OptionNumberRegistry.PROXY_URI && !OptionNumberRegistry.isUriOption(optionNumber) && option.getOptionNumber() != OptionNumberRegistry.BLOCK1 && option.getOptionNumber() != OptionNumberRegistry.BLOCK2) {
			outgoingRequest.setOption(option);
		}
	}

	LOG.finer("Incoming request translated correctly");
	return outgoingRequest;
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:69,代码来源:CoapTranslator.java


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