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


Java Request类代码示例

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


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

示例1: doSendMessage

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
@Override
protected void doSendMessage(Message msg) throws IOException { 
	
	// set token option if required
	if (msg.requiresToken()) {
		msg.setToken( TokenManager.getInstance().acquireToken(true) );
	}
	
	// use overall timeout for clients (e.g., server crash after separate response ACK)
	if (msg instanceof Request) {
		LOG.info(String.format("Requesting response for %s: %s",  ((Request) msg).getUriPath(), msg.sequenceKey()));
		addExchange((Request) msg);
	} else if (msg.getCode()==CodeRegistry.EMPTY_MESSAGE) {
		LOG.info(String.format("Accepting request: %s", msg.key()));
	} else {
		LOG.info(String.format("Responding request: %s", msg.sequenceKey()));
	}
	
	sendMessageOverLowerLayer(msg);
}
 
开发者ID:vitrofp7,项目名称:vitro,代码行数:21,代码来源:TokenLayer.java

示例2: addExchange

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
private RequestResponseSequence addExchange(Request request) {
	
	// create new Transaction
	RequestResponseSequence sequence = new RequestResponseSequence();
	sequence.key = request.sequenceKey();
	sequence.request = request;
	sequence.timeoutTask = new TimeoutTask(sequence);
	
	// associate token with Transaction
	exchanges.put(sequence.key, sequence);
	
	timer.schedule(sequence.timeoutTask, sequenceTimeout);

	LOG.fine(String.format("Stored new exchange: %s", sequence.key));
	
	return sequence;
}
 
开发者ID:vitrofp7,项目名称:vitro,代码行数:18,代码来源:TokenLayer.java

示例3: TransferContext

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
TransferContext(Message msg) {
	
	if (msg instanceof Request) {
		this.cache = msg;
		this.uriPath = msg.getUriPath();
		this.current = (BlockOption) msg.getFirstOption(OptionNumberRegistry.BLOCK1);
	} else if (msg instanceof Response) {
		
		msg.requiresToken(false); // FIXME check if still required after new TokenLayer
		
		this.cache = msg;
		this.uriPath = ((Response)msg).getRequest().getUriPath();
		this.current = (BlockOption) msg.getFirstOption(OptionNumberRegistry.BLOCK2);
	}
	
	LOG.finest(String.format("Created new transfer context for %s: %s", this.uriPath, msg.sequenceKey()));
}
 
开发者ID:vitrofp7,项目名称:vitro,代码行数:18,代码来源:TransferLayer.java

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

示例5: doSendMessage

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
@Override
protected void doSendMessage(Message msg) throws IOException { 
	
	// set token option if required
	if (msg.requiresToken()) {
		msg.setToken( TokenManager.getInstance().acquireToken(true) );
		LOG.info(String.format("Assigned automatic Token for: %s",  msg.sequenceKey()));
	}
	
	// use overall timeout for clients (e.g., server crash after separate response ACK)
	if (msg instanceof Request) {
		LOG.info(String.format("Requesting response for %s: %s",  ((Request) msg).getUriPath(), msg.sequenceKey()));
		addExchange((Request) msg);
	} else if (msg.getCode()==CodeRegistry.EMPTY_MESSAGE) {
		if (msg.getType()==Message.messageType.RST) {
			LOG.info(String.format("Rejecting message: %s", msg.key()));
		} else {
			LOG.info(String.format("Accepting message: %s", msg.key()));
		}
	} else {
		LOG.info(String.format("Responding request: %s", msg.sequenceKey()));
	}
	
	sendMessageOverLowerLayer(msg);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:26,代码来源:TokenLayer.java

示例6: addExchange

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
private synchronized RequestResponseSequence addExchange(Request request) {
	
	// be aware when manually setting tokens, as request/response will be replace
	removeExchange(request.sequenceKey());
	
	// create new Transaction
	RequestResponseSequence sequence = new RequestResponseSequence();
	sequence.key = request.sequenceKey();
	sequence.request = request;
	sequence.timeoutTask = new TimeoutTask(sequence);
	
	// associate token with Transaction
	exchanges.put(sequence.key, sequence);
	
	timer.schedule(sequence.timeoutTask, sequenceTimeout);

	LOG.fine(String.format("Stored new exchange: %s", sequence.key));
	
	return sequence;
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:21,代码来源:TokenLayer.java

示例7: doSendMessage

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
@Override
protected void doSendMessage(Message message) throws IOException {
	// the http stack is intended to send back only coap responses

	// check if the message is a response
	if (message instanceof Response) {
		// retrieve the request linked to the response
		Response response = (Response) message;
		Request request = response.getRequest();
		LOG.info("Handling response for request: " + request);

		// fill the exchanger with the incoming response
		Exchanger<Response> exchanger = exchangeMap.get(request);
		try {
			exchanger.exchange(response);
		} catch (InterruptedException e) {
			LOG.warning("Exchange interrupted: " + e.getMessage());

			// remove the entry from the map
			exchangeMap.remove(request);
			return;
		}

		LOG.info("Exchanged correctly");
	}
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:27,代码来源:HttpStack.java

示例8: addOpenRequest

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
private void addOpenRequest(Request request) {
	
	if (request.getFirstOption(OptionNumberRegistry.OBSERVE)!=null) {
		ObservingManager.getInstance().addSubscription(request);
	} else {
		
		if (ObservingManager.getInstance().hasSubscription(request.sequenceKey())) {
			ObservingManager.getInstance().cancelSubscription(request.sequenceKey());
		}
	
		// create new Transaction
		RequestResponsePair exchange = new RequestResponsePair();
		exchange.key = request.sequenceKey();
		exchange.request = request;
		
		LOG.finer(String.format("Storing open request: %s", exchange.key));
		
		// associate token with Transaction
		pairs.put(exchange.key, exchange);
	}
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:22,代码来源:MatchingLayer.java

示例9: TransferContext

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
TransferContext(Message msg) {
	
	if (msg instanceof Request) {
		this.cache = msg;
		this.uriPath = msg.getUriPath();
		this.uriQuery = msg.getUriQuery();
		this.current = (BlockOption) msg.getFirstOption(OptionNumberRegistry.BLOCK1);
	} else if (msg instanceof Response) {
		
		msg.requiresToken(false); // FIXME check if still required after new TokenLayer
		
		this.cache = msg;
		this.uriPath = ((Response)msg).getRequest().getUriPath();
		this.uriQuery = ((Response)msg).getRequest().getUriQuery();
		this.current = (BlockOption) msg.getFirstOption(OptionNumberRegistry.BLOCK2);
	}
	
	LOG.finest(String.format("Created new transfer context for %s%s: %s", this.uriPath, this.uriQuery, msg.sequenceKey()));
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:20,代码来源:TransferLayer.java

示例10: fromContentTypeOption

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
/**
 * Create a key for the cache starting from a request and the
 * content-type of the corresponding response.
 * 
 * @param request
 * @return
 * @throws URISyntaxException
 */
private static CacheKey fromContentTypeOption(Request request) throws URISyntaxException {
	if (request == null) {
		throw new IllegalArgumentException("request == null");
	}

	Response response = request.getResponse();
	if (response == null) {
		return fromAcceptOptions(request).get(0);
	}

	String proxyUri = request.getProxyUri().toString();
	int mediaType = response.getContentType();
	byte[] payload = request.getPayload();

	// create the new cacheKey
	CacheKey cacheKey = new CacheKey(proxyUri, mediaType, payload);
	cacheKey.setResponse(response);

	return cacheKey;
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:29,代码来源:ProxyCacheResource.java

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

示例12: getCoapContentTypeHeaderSemiColonTest

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
@Test
public final void getCoapContentTypeHeaderSemiColonTest() throws UnsupportedEncodingException {
	// create the http message and associate the entity
	HttpRequest httpRequest = new BasicHttpEntityEnclosingRequest("get", "http://localhost");
	HttpEntity httpEntity = new ByteArrayEntity("aaa".getBytes(Charset.forName("ISO-8859-1")));
	((BasicHttpEntityEnclosingRequest) httpRequest).setEntity(httpEntity);

	// create the header
	httpRequest.setHeader("content-type", "text/plain; charset=iso-8859-1");

	Request coapRequest = new GETRequest();

	// set the content-type
	int coapContentType = HttpTranslator.getCoapMediaType(httpRequest);
	coapRequest.setContentType(coapContentType);

	assertEquals(coapRequest.getContentType(), MediaTypeRegistry.TEXT_PLAIN);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:19,代码来源:HttpTranslatorTest.java

示例13: getCoapContentTypeHeaderTest

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
@Test
public final void getCoapContentTypeHeaderTest() throws UnsupportedEncodingException {
	// create the http message and associate the entity
	HttpRequest httpRequest = new BasicHttpEntityEnclosingRequest("get", "http://localhost");
	HttpEntity httpEntity = new ByteArrayEntity("aaa".getBytes());
	((BasicHttpEntityEnclosingRequest) httpRequest).setEntity(httpEntity);

	// create the header
	httpRequest.setHeader("content-type", "text/plain");

	Request coapRequest = new GETRequest();

	// set the content-type
	int coapContentType = HttpTranslator.getCoapMediaType(httpRequest);
	coapRequest.setContentType(coapContentType);

	assertEquals(MediaTypeRegistry.TEXT_PLAIN, coapRequest.getContentType());
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:19,代码来源:HttpTranslatorTest.java

示例14: getCoapContentTypeUnknownTest

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
@Test
public final void getCoapContentTypeUnknownTest() throws UnsupportedEncodingException {
	// create the http message and associate the entity
	HttpRequest httpRequest = new BasicHttpEntityEnclosingRequest("get", "http://localhost");
	HttpEntity httpEntity = new ByteArrayEntity("aaa".getBytes());
	((BasicHttpEntityEnclosingRequest) httpRequest).setEntity(httpEntity);

	// create the header
	httpRequest.setHeader("content-type", "multipart/form-data");

	Request coapRequest = new GETRequest();

	// set the content-type
	int coapContentType = HttpTranslator.getCoapMediaType(httpRequest);
	coapRequest.setContentType(coapContentType);

	assertEquals(coapRequest.getContentType(), MediaTypeRegistry.APPLICATION_OCTET_STREAM);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:19,代码来源:HttpTranslatorTest.java

示例15: getCoapRequestLocalResourceTest

import ch.ethz.inf.vs.californium.coap.Request; //导入依赖的package包/类
@Test
public final void getCoapRequestLocalResourceTest() throws TranslationException {
	String resourceName = "localResource";
	String resourceString = "/" + resourceName;

	for (String httpMethod : COAP_METHODS) {
		// create the http request
		RequestLine requestLine = new BasicRequestLine(httpMethod, resourceString, HttpVersion.HTTP_1_1);
		HttpRequest httpRequest = new BasicHttpRequest(requestLine);

		// translate the request
		Request coapRequest = HttpTranslator.getCoapRequest(httpRequest, PROXY_RESOURCE, true);
		assertNotNull(coapRequest);

		// check the method translation
		int coapMethod = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.request.method." + httpMethod));
		assertTrue(coapRequest.getCode() == coapMethod);

		// check the uri-path
		String uriPath = coapRequest.getFirstOption(OptionNumberRegistry.URI_PATH).getStringValue();
		assertEquals(uriPath, resourceName);

		// check the absence of the proxy-uri option
		assertNull(coapRequest.getFirstOption(OptionNumberRegistry.PROXY_URI));
	}
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:27,代码来源:HttpTranslatorTest.java


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