本文整理了Java中javax.ws.rs.core.Response.getMediaType
方法的一些代码示例,展示了Response.getMediaType
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getMediaType
方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:getMediaType
[英]Get the media type of the message entity.
[中]获取消息实体的媒体类型。
代码示例来源:origin: jersey/jersey
@Override
public int read() throws IOException {
if (byteArrayInputStream == null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream stream = null;
try {
try {
stream = requestContext.getWorkers().writeTo(
entity, entity.getClass(), null, null, response.getMediaType(),
response.getMetadata(), requestContext.getPropertiesDelegate(), baos,
Collections.<WriterInterceptor>emptyList());
} finally {
if (stream != null) {
stream.close();
}
}
} catch (IOException e) {
// ignore
}
byteArrayInputStream = new ByteArrayInputStream(baos.toByteArray());
}
return byteArrayInputStream.read();
}
};
代码示例来源:origin: jersey/jersey
@Override
public int read() throws IOException {
if (byteArrayInputStream == null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream stream = null;
try {
try {
stream = requestContext.getWorkers().writeTo(
entity, entity.getClass(), null, null, response.getMediaType(),
response.getMetadata(), requestContext.getPropertiesDelegate(), baos,
Collections.<WriterInterceptor>emptyList());
} finally {
if (stream != null) {
stream.close();
}
}
} catch (IOException e) {
// ignore
}
byteArrayInputStream = new ByteArrayInputStream(baos.toByteArray());
}
return byteArrayInputStream.read();
}
};
代码示例来源:origin: org.glassfish.jersey.core/jersey-client
@Override
public int read() throws IOException {
if (byteArrayInputStream == null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream stream = null;
try {
try {
stream = requestContext.getWorkers().writeTo(
entity, entity.getClass(), null, null, response.getMediaType(),
response.getMetadata(), requestContext.getPropertiesDelegate(), baos,
Collections.<WriterInterceptor>emptyList());
} finally {
if (stream != null) {
stream.close();
}
}
} catch (IOException e) {
// ignore
}
byteArrayInputStream = new ByteArrayInputStream(baos.toByteArray());
}
return byteArrayInputStream.read();
}
};
代码示例来源:origin: hugegraph/hugegraph
private Response doGetRequest(String location, String auth, String query) {
String url = String.format("%s?%s", location, query);
Response r = this.client.target(url)
.request()
.header(HttpHeaders.AUTHORIZATION, auth)
.accept(MediaType.APPLICATION_JSON)
.acceptEncoding(CompressInterceptor.GZIP)
.get();
if (r.getMediaType() != null) {
// Append charset
assert MediaType.APPLICATION_JSON_TYPE.equals(r.getMediaType());
r.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE,
r.getMediaType().withCharset(CHARSET));
}
gremlinInputHistogram.update(query.length());
gremlinOutputHistogram.update(r.getLength());
return r;
}
代码示例来源:origin: hugegraph/hugegraph
private Response doPostRequest(String location, String auth, String req) {
Entity<?> body = Entity.entity(req, MediaType.APPLICATION_JSON);
Response r = this.client.target(location)
.request()
.header(HttpHeaders.AUTHORIZATION, auth)
.accept(MediaType.APPLICATION_JSON)
.acceptEncoding(CompressInterceptor.GZIP)
.post(body);
if (r.getMediaType() != null) {
// Append charset
assert MediaType.APPLICATION_JSON_TYPE.equals(r.getMediaType());
r.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE,
r.getMediaType().withCharset(CHARSET));
}
gremlinInputHistogram.update(req.length());
gremlinOutputHistogram.update(r.getLength());
return r;
}
代码示例来源:origin: jamesagnew/hapi-fhir
@Override
public String getMimeType() {
MediaType mediaType = myResponse.getMediaType();
if (mediaType == null) {
return null;
}
//Keep only type and subtype and do not include the parameters such as charset
return new MediaType(mediaType.getType(), mediaType.getSubtype()).toString();
}
代码示例来源:origin: resteasy/Resteasy
if (response.getMediaType() == null)
if (response.getMediaType() == null)
response.close();
if (response.getMediaType() == null)
response.close();
代码示例来源:origin: org.ligoj.bootstrap/bootstrap-business
/**
* Update response for a forbidden access.
*/
private void updateForbiddenAccess(final HttpServletResponse response) throws IOException {
final Response response2 = accessDeniedHelper.toResponse(new AccessDeniedException(""));
response.setStatus(response2.getStatus());
response.setContentType(response2.getMediaType().toString());
response.getOutputStream().write(((String) response2.getEntity()).getBytes(StandardCharsets.UTF_8));
}
代码示例来源:origin: mesosphere/dcos-commons
private static void checkJsonOkResponse(String expectedContent, Response r) {
assertEquals(200, r.getStatus());
assertEquals(MediaType.APPLICATION_JSON_TYPE, r.getMediaType());
assertEquals(expectedContent, r.getEntity().toString());
}
}
代码示例来源:origin: apache/cxf
@Test
public void testUiRootResource() {
// Test that Swagger UI resources do not interfere with
// application-specific ones and are accessible.
WebClient uiClient = WebClient
.create(getBaseUrl() + "/api-docs")
.accept("*/*");
try (Response response = uiClient.get()) {
String html = response.readEntity(String.class);
assertThat(html, containsString("<!-- HTML"));
assertThat(response.getMediaType(), equalTo(MediaType.TEXT_HTML_TYPE));
}
}
代码示例来源:origin: apache/cxf
@Test
public void testUiResource() {
// Test that Swagger UI resources do not interfere with
// application-specific ones and are accessible.
WebClient uiClient = WebClient
.create(getBaseUrl() + "/swagger-ui.css")
.accept("text/css");
try (Response response = uiClient.get()) {
String css = response.readEntity(String.class);
assertThat(css, containsString(".swagger-ui{"));
assertThat(response.getMediaType(), equalTo(MediaType.valueOf("text/css")));
}
}
代码示例来源:origin: apache/cxf
@Test
public void testResponseHasBeenReceivedWhenQueringAllBookAsAtomFeed() {
Response r = createWebClient(getBasePath() + "/books/feed", "application/atom+xml").get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
assertEquals("application/atom+xml", r.getMediaType().toString());
}
代码示例来源:origin: apache/cxf
@Test
public void testResponseHasBeenReceivedWhenQueringAllBookAsAtomFeed() {
Response r = createWebClient(getBasePath() + "/books/feed", "application/atom+xml").get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
assertEquals("application/atom+xml", r.getMediaType().toString());
}
代码示例来源:origin: apache/cxf
@Test
public void testResponseHasBeenReceivedWhenQueringAllBookAsAtomFeed() {
Response r = createWebClient(getBasePath() + "/books/feed", "application/atom+xml").get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
assertEquals("application/atom+xml", r.getMediaType().toString());
}
代码示例来源:origin: apache/cxf
@Test
public void testResponseHasBeenReceivedWhenQueringAllBookAsAtomFeed() {
Response r = createWebClient(getBasePath() + "/books/feed", "application/atom+xml").get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
assertEquals("application/atom+xml", r.getMediaType().toString());
}
代码示例来源:origin: apache/cxf
@Test
public void testUseMapperOnBus() {
String address = "http://localhost:" + PORT + "/bookstore/mapperonbus";
WebClient wc = WebClient.create(address);
Response r = wc.post(null);
assertEquals(500, r.getStatus());
MediaType mt = r.getMediaType();
assertEquals("text/plain;charset=utf-8", mt.toString().toLowerCase());
assertEquals("the-mapper", r.getHeaderString("BusMapper"));
assertEquals("BusMapperException", r.readEntity(String.class));
}
代码示例来源:origin: apache/cxf
@Test
public void testGetBookDescriptionHttpResponse() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/httpresponse";
WebClient wc = WebClient.create(address);
WebClient.getConfig(wc).getInInterceptors().add(new LoggingInInterceptor());
Response r = wc.get();
assertEquals("text/plain", r.getMediaType().toString());
assertEquals("Good Book", r.readEntity(String.class));
}
代码示例来源:origin: apache/cxf
@Test
public void testStatusAngHeadersFromStream() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/books/statusFromStream";
WebClient wc = WebClient.create(address);
wc.accept("text/xml");
Response r = wc.get();
assertEquals(503, r.getStatus());
assertEquals("text/custom+plain", r.getMediaType().toString());
assertEquals("CustomValue", r.getHeaderString("CustomHeader"));
assertEquals("Response is not available", r.readEntity(String.class));
}
代码示例来源:origin: apache/cxf
@Test
public void testGetCustomBookText() {
String address = "http://localhost:" + PORT + "/bookstore/customtext";
WebClient wc = WebClient.create(address);
Response r = wc.accept("text/custom").get();
String name = r.readEntity(String.class);
assertEquals("Good book", name);
assertEquals("text/custom;charset=us-ascii", r.getMediaType().toString());
assertEquals("CustomValue", r.getHeaderString("CustomHeader"));
}
代码示例来源:origin: apache/cxf
private void validateResponse(WebClient wc) {
Response response = wc.getResponse();
assertEquals("OK", response.getHeaderString("Response"));
assertEquals("OK2", response.getHeaderString("Response2"));
assertEquals("Dynamic", response.getHeaderString("DynamicResponse"));
assertEquals("Dynamic2", response.getHeaderString("DynamicResponse2"));
assertEquals("custom", response.getHeaderString("Custom"));
assertEquals("simple", response.getHeaderString("Simple"));
assertEquals("serverWrite", response.getHeaderString("ServerWriterInterceptor"));
assertEquals("application/xml;charset=us-ascii", response.getMediaType().toString());
assertEquals("http://localhost/redirect", response.getHeaderString(HttpHeaders.LOCATION));
}
内容来源于网络,如有侵权,请联系作者删除!