當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。