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


Java Request.setOption方法代码示例

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


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

示例1: getHttpHeadersTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
/**
 * Test method for
 * {@link ch.ethz.inf.vs.californium.util.HttpTranslator#getHttpHeaders(ch.ethz.inf.vs.californium.coap.Message)}
 * .
 */
@Test
public final void getHttpHeadersTest() {
	// create the request
	Request coapRequest = new GETRequest();

	// set the options
	String etag = "1235234636547";
	coapRequest.setOption(new Option(etag, OptionNumberRegistry.ETAG));

	// translate the message
	Header[] headers = HttpTranslator.getHttpHeaders(coapRequest.getOptions());

	assertNotNull(headers);
	assertTrue(headers.length == 1);
	assertEquals(headers[0].getName().toLowerCase(), OptionNumberRegistry.toString(OptionNumberRegistry.ETAG).toLowerCase());
	assertEquals(headers[0].getValue().toLowerCase(), etag.toLowerCase());
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:23,代码来源:HttpTranslatorTest.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: getHttpHeadersUnknownOptionTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
@Test
public final void getHttpHeadersUnknownOptionTest() {
	// create the request
	Request coapRequest = new GETRequest();
	coapRequest.setOption(new Option("coap://localhost:5683/resource", OptionNumberRegistry.PROXY_URI));
	coapRequest.setOption(new Option("EDCS", OptionNumberRegistry.BLOCK1));

	// translate the message
	Header[] headers = HttpTranslator.getHttpHeaders(coapRequest.getOptions());

	assertNotNull(headers);
	assertTrue(headers.length == 0);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:14,代码来源:HttpTranslatorTest.java

示例4: getHttpRequestMalformedProxyUriTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
@Test(expected = TranslationException.class)
public final void getHttpRequestMalformedProxyUriTest() throws TranslationException {
	// create the request
	Request coapRequest = new GETRequest();
	coapRequest.setOption(new Option("coap:??=)(&)&%//localhost:=)??=)/?)%£$$!&5683/resource", OptionNumberRegistry.PROXY_URI));

	// translate the message
	HttpTranslator.getHttpRequest(coapRequest);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:10,代码来源:HttpTranslatorTest.java

示例5: getHttpRequestTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
/**
 * Test method for
 * {@link ch.ethz.inf.vs.californium.util.HttpTranslator#getHttpRequest(ch.ethz.inf.vs.californium.coap.Request)}
 * .
 * 
 * @throws TranslationException
 */
@Test
public final void getHttpRequestTest() throws TranslationException {
	// create the coap request
	Request coapRequest = new GETRequest();
	coapRequest.setOption(new Option("coap://localhost:5683/resource", OptionNumberRegistry.PROXY_URI));

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

	// check
	assertNotNull(httpRequest);
	assertTrue(httpRequest.getAllHeaders().length == 0);
	assertEquals(httpRequest.getClass(), BasicHttpRequest.class);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:22,代码来源:HttpTranslatorTest.java

示例6: 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

示例7: 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.setOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。