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


Java Response.getMetadata方法代码示例

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


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

示例1: addHeaders

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private static void addHeaders(Response jaxrsResponse, HttpServerResponse response) {

		if (jaxrsResponse.getMetadata() != null) {

			List<Object> cookies = jaxrsResponse.getMetadata().get(HttpHeaders.SET_COOKIE.toString());
			if (cookies != null) {

				Iterator<Object> it = cookies.iterator();
				while (it.hasNext()) {
					Object next = it.next();
					if (next instanceof NewCookie) {

						NewCookie cookie = (NewCookie) next;
						response.putHeader(HttpHeaders.SET_COOKIE, cookie.toString());

						it.remove();
					}
				}

				if (cookies.size() < 1) {
					jaxrsResponse.getMetadata().remove(HttpHeaders.SET_COOKIE.toString());
				}
			}
		}

		if (jaxrsResponse.getMetadata() != null && jaxrsResponse.getMetadata().size() > 0) {

			for (String name : jaxrsResponse.getMetadata().keySet()) {
				List<Object> meta = jaxrsResponse.getMetadata().get(name);

				if (meta != null && meta.size() > 0) {
					for (Object item : meta) {
						if (item != null) {
							response.putHeader(name, item.toString());
						}
					}
				}
			}
		}
	}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:41,代码来源:JaxResponseWriter.java

示例2: PersoniumCoreContainerFilter

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること.
 * @throws URISyntaxException URISyntaxException
 */
@Test
public void 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること() throws URISyntaxException {
    // 被テストオブジェクトを準備
    PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter();
    // ContainerRequiestを準備
    WebApplication wa = mock(WebApplication.class);
    InBoundHeaders headers = new InBoundHeaders();
    // X-FORWARDED-* 系のヘッダ設定
    String scheme = "https";
    String host = "example.org";
    headers.add(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme);
    headers.add(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_HOST, host);
    ContainerRequest request = new ContainerRequest(wa, HttpMethod.OPTIONS,
            new URI("http://dc1.example.com/hoge"),
            new URI("http://dc1.example.com/hoge/hoho"),
            headers, null);
    // HttpServletRequestのmockを準備
    HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
    when(mockServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://dc1.example.com"));
    ServletContext mockServletContext = mock(ServletContext.class);
    when(mockServletContext.getContextPath()).thenReturn("");
    when(mockServletRequest.getServletContext()).thenReturn(mockServletContext);
    containerFilter.setHttpServletRequest(mockServletRequest);
    try {
        containerFilter.filter(request);
    } catch (WebApplicationException e) {
        Response response = e.getResponse();
        assertEquals(response.getStatus(), HttpStatus.SC_OK);
        MultivaluedMap<String, Object> meta = response.getMetadata();
        List<Object> values = meta.get("Access-Control-Allow-Methods");
        assertEquals(values.size(), 1);
        String value = (String) values.get(0);
        String[] methods = value.split(",");
        Map<String, String> masterMethods = new HashMap<String, String>();
        masterMethods.put(HttpMethod.OPTIONS, "");
        masterMethods.put(HttpMethod.GET, "");
        masterMethods.put(HttpMethod.POST, "");
        masterMethods.put(HttpMethod.PUT, "");
        masterMethods.put(HttpMethod.DELETE, "");
        masterMethods.put(HttpMethod.HEAD, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MERGE, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MKCOL, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MOVE, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPFIND, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPPATCH, "");
        masterMethods.put(io.personium.common.utils.PersoniumCoreUtils.HttpMethod.ACL, "");
        for (String method : methods) {
            if (method.trim() == "") {
                continue;
            }
            String m = masterMethods.remove(method.trim());
            if (m == null) {
                fail("Method " + method + " is not defined.");
            }
        }
        if (!masterMethods.isEmpty()) {
            fail("UnExcpected Error.");
        }
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:65,代码来源:OptionsMethodTest.java


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