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


Java Response.getMediaType方法代码示例

本文整理汇总了Java中javax.ws.rs.core.Response.getMediaType方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getMediaType方法的具体用法?Java Response.getMediaType怎么用?Java Response.getMediaType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.core.Response的用法示例。


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

示例1: testNullResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testNullResponse() throws Exception {
	// GIVEN
	// mapping of null responses to JSON-API disabled
	Assume.assumeFalse(enableNullResponse);

	// WHEN
	Response response = get("/repositoryActionWithNullResponse", null);

	// THEN
	Assert.assertNotNull(response);
	assertThat(response.getStatus())
			.describedAs("Status code")
			.isEqualTo(Response.Status.NO_CONTENT.getStatusCode());
	MediaType mediaType = response.getMediaType();
	assertThat(mediaType)
			.describedAs("Media-Type")
			.isEqualTo(null);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:20,代码来源:JsonApiResponseFilterTestBase.java

示例2: testNonInterfaceMethodWithNullResponseJsonApi

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testNonInterfaceMethodWithNullResponseJsonApi() throws Exception {
	// GIVEN
	// mapping of null responses to JSON-API disabled
	Assume.assumeFalse(enableNullResponse);

	// WHEN
	Response response = get("/nonInterfaceMethodWithNullResponseJsonApi", null);

	// THEN
	Assert.assertNotNull(response);
	assertThat(response.getStatus())
			.describedAs("Status code")
			.isEqualTo(Response.Status.NO_CONTENT.getStatusCode());
	MediaType mediaType = response.getMediaType();
	assertThat(mediaType)
			.describedAs("Media-Type")
			.isEqualTo(null);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:20,代码来源:JsonApiResponseFilterTestBase.java

示例3: testNonInterfaceMethodWithNullResponseJsonApiWrapped

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testNonInterfaceMethodWithNullResponseJsonApiWrapped() throws Exception {
	// GIVEN
	// mapping of null responses to JSON-API enabled
	Assume.assumeTrue(enableNullResponse);

	// WHEN
	Response response = get("/nonInterfaceMethodWithNullResponseJsonApi", null);

	// THEN
	Assert.assertNotNull(response);
	assertThat(response.getStatus())
			.describedAs("Status code")
			.isEqualTo(Response.Status.OK.getStatusCode());

	MediaType mediaType = response.getMediaType();
	assertThat(mediaType)
			.describedAs("Media-Type")
			.isEqualTo(JsonApiMediaType.APPLICATION_JSON_API_TYPE);
	String schedule = response.readEntity(String.class);
	assertThat(schedule)
			.describedAs("Response content")
			.isEqualTo("{\"data\":null}");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:25,代码来源:JsonApiResponseFilterTestBase.java

示例4: testStringResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testStringResponse() throws Exception {
	// GIVEN
	Map<String, String> queryParams = new HashMap<>();
	queryParams.put("msg", "msg");

	// WHEN
	Response response = get("/repositoryAction", queryParams);

	// THEN
	Assert.assertNotNull(response);
	assertThat(response.getStatus())
			.describedAs("Status code")
			.isEqualTo(Response.Status.OK.getStatusCode());

	MediaType mediaType = response.getMediaType();
	assertThat(mediaType)
			.describedAs("Media-Type")
			.isEqualTo(MediaType.TEXT_HTML_TYPE);
	String entity = response.readEntity(String.class);
	assertThat(entity)
			.describedAs("Response content")
			.isEqualTo("repository action: msg");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:25,代码来源:JsonApiResponseFilterTestBase.java

示例5: testStringResponseWrapped

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testStringResponseWrapped() throws Exception {
	// GIVEN
	Map<String, String> queryParams = new HashMap<>();
	queryParams.put("msg", "msg");

	// WHEN
	Response response = get("/repositoryActionJsonApi", queryParams);

	// THEN
	Assert.assertNotNull(response);
	assertThat(response.getStatus())
			.describedAs("Status code")
			.isEqualTo(Response.Status.OK.getStatusCode());

	MediaType mediaType = response.getMediaType();
	assertThat(mediaType)
			.describedAs("Media-Type")
			.isEqualTo(JsonApiMediaType.APPLICATION_JSON_API_TYPE);
	String entity = response.readEntity(String.class);
	assertThat(entity)
			.describedAs("Response content")
			.isEqualTo("{\"data\":\"repository action: msg\"}");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:25,代码来源:JsonApiResponseFilterTestBase.java

示例6: testErrorResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testErrorResponse() throws Exception {
	// GIVEN

	// WHEN
	Response response = get("/repositoryActionWithException", null);

	// THEN
	Assert.assertNotNull(response);
	assertThat(response.getStatus())
			.describedAs("Status code")
			.isEqualTo(Response.Status.FORBIDDEN.getStatusCode());

	MediaType mediaType = response.getMediaType();
	assertThat(mediaType)
			.describedAs("Media-Type")
			.isEqualTo(JsonApiMediaType.APPLICATION_JSON_API_TYPE);
	String error = response.readEntity(String.class);
	assertThat(error)
			.describedAs("Response content")
			.startsWith("{\"errors\":");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:23,代码来源:JsonApiResponseFilterTestBase.java

示例7: testJsonApiResourceResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testJsonApiResourceResponse() throws Exception {
	// GIVEN

	// WHEN
	Response response = get("/repositoryActionWithResourceResult", null);

	// THEN
	Assert.assertNotNull(response);
	assertThat(response.getStatus())
			.describedAs("Status code")
			.isEqualTo(Response.Status.OK.getStatusCode());

	MediaType mediaType = response.getMediaType();
	assertThat(mediaType)
			.describedAs("Media-Type")
			.isEqualTo(JsonApiMediaType.APPLICATION_JSON_API_TYPE);
	String schedule = response.readEntity(String.class);
	assertThat(schedule)
			.describedAs("Response content")
			.startsWith("{\"data\":").contains("\"links\":{");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:23,代码来源:JsonApiResponseFilterTestBase.java

示例8: write

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public void write(
        final MinijaxRequestContext context,
        final Response response,
        final HttpServletResponse servletResponse)
                throws IOException {

    servletResponse.setStatus(response.getStatus());

    for (final Entry<String, List<Object>> entry : response.getHeaders().entrySet()) {
        final String name = entry.getKey();
        for (final Object value : entry.getValue()) {
            servletResponse.addHeader(name, value.toString());
        }
    }

    if (context.getMethod().equals("OPTIONS")) {
        return;
    }

    final MediaType mediaType = response.getMediaType();
    if (mediaType != null) {
        servletResponse.setContentType(mediaType.toString());
    }

    final Object obj = response.getEntity();
    if (obj == null) {
        return;
    }

    final MessageBodyWriter writer = providers.getMessageBodyWriter(obj.getClass(), null, null, mediaType);
    if (writer != null) {
        writer.writeTo(obj, obj.getClass(), null, null, mediaType, null, servletResponse.getOutputStream());
        return;
    }

    // What to do
    servletResponse.getWriter().println(obj.toString());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:40,代码来源:MinijaxApplication.java


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