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


Java Request.setContentType方法代码示例

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


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

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

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

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

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

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

示例6: getCoapContentTypeTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
/**
 * Test method for
 * {@link ch.ethz.inf.vs.californium.util.HttpTranslator#getCoapContentType(org.apache.http.HttpMessage, ch.ethz.inf.vs.californium.coap.Message)}
 * .
 * 
 * @throws UnsupportedEncodingException
 */
@Test
public final void getCoapContentTypeTest() throws UnsupportedEncodingException {
	// create the http message and associate the entity
	HttpRequest httpRequest = new BasicHttpEntityEnclosingRequest("get", "http://localhost");
	HttpEntity httpEntity = new StringEntity("aaa");
	((BasicHttpEntityEnclosingRequest) httpRequest).setEntity(httpEntity);
	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,代码行数:22,代码来源:HttpTranslatorTest.java

示例7: getHttpHeadersContentTypeTest

import ch.ethz.inf.vs.californium.coap.Request; //导入方法依赖的package包/类
@Test
public final void getHttpHeadersContentTypeTest() {
	// create the request
	Request coapRequest = new GETRequest();
	coapRequest.setContentType(MediaTypeRegistry.TEXT_PLAIN);

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

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


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