本文整理汇总了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);
}
示例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());
}
示例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);
}
示例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()));
}
示例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()));
}
示例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);
}
示例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);
}