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


Java Request.getProxyUri方法代码示例

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


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

示例1: manageProxyUriRequest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
/**
 * Manage proxy uri request.
 * 
 * @param request
 *            the request
 * @throws URISyntaxException
 *             the uRI syntax exception
 */
private void manageProxyUriRequest(Request request) throws URISyntaxException {
	// check which schema is requested
	URI proxyUri = request.getProxyUri();

	// the local resource that will abstract the client part of the
	// proxy
	String clientPath;

	// switch between the schema requested
	if (proxyUri.getScheme() != null && proxyUri.getScheme().matches("^http.*")) {
		// the local resource related to the http client
		clientPath = PROXY_HTTP_CLIENT;
	} else {
		// the local resource related to the http client
		clientPath = PROXY_COAP_CLIENT;
	}

	// set the path in the request to be forwarded correctly
	List<Option> uriPath = Option.split(OptionNumberRegistry.URI_PATH, clientPath, "/");
	request.setOptions(uriPath);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:30,代码来源:ProxyEndpoint.java

示例2: updateStatistics

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
public void updateStatistics(Request request, boolean cachedResponse) {
	URI proxyUri = null;
	try {
		proxyUri = request.getProxyUri();
	} catch (URISyntaxException e) {
		LOG.warning(String.format("Proxy-uri malformed: %s", request.getFirstOption(OptionNumberRegistry.PROXY_URI)));
	}

	if (proxyUri == null) {
		// throw new IllegalArgumentException("proxyUri == null");
		return;
	}

	// manage the address requester
	String addressString = proxyUri.getHost();
	if (addressString != null) {
		// manage the resource requested
		String resourceString = proxyUri.getPath();
		if (resourceString != null) {
			// check if there is already an entry for the row/column
			// association
			StatHelper statHelper = statsTable.get(addressString, resourceString);
			if (statHelper == null) {
				// create a new stat if it not present
				statHelper = new StatHelper();

				// add the new element to the table
				statsTable.put(addressString, resourceString, statHelper);
			}

			// increment the count of the requests
			statHelper.increment(cachedResponse);
		}
	}
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:36,代码来源:StatsResource.java

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

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