javax.ws.rs.core.Response.getHeaderString()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(268)

本文整理了Java中javax.ws.rs.core.Response.getHeaderString方法的一些代码示例,展示了Response.getHeaderString的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getHeaderString方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:getHeaderString

Response.getHeaderString介绍

[英]Get a message header as a single string value. Each single header value is converted to String using a javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate if one is available via javax.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)for the header value class or using its toString method if a header delegate is not available.
[中]

代码示例

代码示例来源:origin: jersey/jersey

/**
 * Get the {@code WWW-Authenticate} header of the request that cause the exception.
 *
 * @return {@code WWW-Authenticate} header value.
 */
public String getWwwAuthHeader() {
  return super.getResponse().getHeaderString(HttpHeaders.WWW_AUTHENTICATE);
}

代码示例来源:origin: liferay/liferay-portal

private Response _follow3Redirects(Response currentResponse) {
  Response.StatusType statusType = currentResponse.getStatusInfo();
  if (statusType.getFamily() != Response.Status.Family.REDIRECTION) {
    return currentResponse;
  }
  AtomicInteger counter = new AtomicInteger();
  Response response = currentResponse;
  while ((statusType.getFamily() == Response.Status.Family.REDIRECTION) &&
      (counter.incrementAndGet() <= 3)) {
    String location = response.getHeaderString(HttpHeaders.LOCATION);
    if (StringUtils.isEmpty(location)) {
      return response;
    }
    if (_log.isDebugEnabled()) {
      _log.debug(
        "Redirect location {}#: {}", counter.get(), location);
    }
    response.close();
    WebTarget webTarget = _client.target(location);
    Invocation.Builder builder = webTarget.request(APPLICATION_JSON_LD);
    response = builder.get();
  }
  return response;
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testConsole() {
 Response response = target("/index.html").request().accept(MediaType.TEXT_HTML).get();
 Assert.assertEquals("public", response.getHeaderString("Cache-Control"));
 Assert.assertEquals("SAMEORIGIN", response.getHeaderString("X-Frame-Options"));
 String html = response.readEntity(String.class);
 String[] substrings = {
   "DOCTYPE",
   "Oryx Serving Layer",
   "Alternating Least Squares",
   "/recommend",
   "<form"
 };
 for (String substring : substrings) {
  Assert.assertTrue("Doesn't contain " + substring, html.contains(substring));
 }
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testConsole() {
 Response response = target("/index.html").request().accept(MediaType.TEXT_HTML).get();
 Assert.assertEquals("public", response.getHeaderString("Cache-Control"));
 Assert.assertEquals("SAMEORIGIN", response.getHeaderString("X-Frame-Options"));
 String html = response.readEntity(String.class);
 String[] substrings = {
   "DOCTYPE",
   "Oryx Serving Layer",
   "Random Decision Forests",
   "/predict",
   "<form"
 };
 for (String substring : substrings) {
  Assert.assertTrue("Doesn't contain " + substring, html.contains(substring));
 }
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testConsole() {
 Response response = target("/index.html").request().accept(MediaType.TEXT_HTML).get();
 Assert.assertEquals("public", response.getHeaderString("Cache-Control"));
 Assert.assertEquals("SAMEORIGIN", response.getHeaderString("X-Frame-Options"));
 String html = response.readEntity(String.class);
 String[] substrings = {
   "DOCTYPE",
   "Oryx Serving Layer",
   "K-means",
   "/assign",
   "<form"
 };
 for (String substring : substrings) {
  Assert.assertTrue("Doesn't contain " + substring, html.contains(substring));
 }
}

代码示例来源:origin: apache/cxf

public BookNotFoundFault fromResponse(Response r) {
  String status = r.getHeaderString("Status");
  if ("notFound".equals(status)) {
    return new BookNotFoundFault(status);
  }
  return null;
}

代码示例来源: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));
}

代码示例来源:origin: apache/cxf

private void validatePostResponse(WebClient wc, boolean async, boolean bodyEmpty) {
  validateResponse(wc);
  Response response = wc.getResponse();
  assertEquals(!async ? "serverRead" : "serverReadAsync",
    response.getHeaderString("ServerReaderInterceptor"));
  if (!bodyEmpty) {
    assertEquals("clientWrite", response.getHeaderString("ClientWriterInterceptor"));
  } else {
    assertEquals("true", response.getHeaderString("EmptyRequestStreamDetected"));
  }
  assertEquals("clientRead", response.getHeaderString("ClientReaderInterceptor"));
}

代码示例来源:origin: apache/cxf

@Test
  public void testInterceptorInvokedOnFormAndFormParamMatchesFormValue() throws Exception {
    Client client = ClientBuilder.newClient();
    String uri = "http://localhost:" + PORT + "/form";
    Form f = new Form("value", "ORIGINAL");
    Response r = client.target(uri)
              .request(MediaType.APPLICATION_FORM_URLENCODED)
              .post(Entity.form(f));

    Assert.assertEquals("MODIFIED", r.getHeaderString("FromForm"));
    Assert.assertEquals("MODIFIED", r.getHeaderString("FromFormParam"));
  }
}

代码示例来源: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 testGetBookNameAsByteArray() {
  String address = "http://localhost:" + PORT + "/bookstore/booknames/123";
  WebClient wc = WebClient.create(address);
  Response r = wc.accept("application/bar").get();
  String name = r.readEntity(String.class);
  assertEquals("CXF in Action", name);
  String lengthStr = r.getHeaderString(HttpHeaders.CONTENT_LENGTH);
  assertNotNull(lengthStr);
  long length = Long.valueOf(lengthStr);
  assertEquals(name.length(), length);
}

代码示例来源:origin: apache/cxf

@Test
public void testBookWithExceptionsNoMapper() throws Exception {
  BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT,
                        BookStore.class);
  try {
    store.getBookWithExceptions(true);
    fail();
  } catch (WebApplicationException ex) {
    assertEquals("notReturned", ex.getResponse().getHeaderString("Status"));
  }
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBookRetryAfter() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/books/query/default";
  WebClient wc = WebClient.create(address);
  Response r = wc.get();
  assertEquals(503, r.getStatus());
  assertEquals("2", r.getHeaderString("Retry-After"));
}
@Test

代码示例来源:origin: apache/cxf

@Test
public void testEchoBook() throws Exception {
  URL url = new URL("http://localhost:" + PORT + "/test/5/bookstorestorage/thosebooks");
  WebClient wc = WebClient.create(url.toString(),
                  Collections.singletonList(new CustomJaxbElementProvider()));
  Response r = wc.type("application/xml").post(new Book("proxy", 333L));
  Book book = r.readEntity(Book.class);
  assertEquals(333L, book.getId());
  String ct = r.getHeaderString("Content-Type");
  assertEquals("application/xml;a=b", ct);
}

代码示例来源: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

protected void doTestTimeoutAndCancel(String baseAddress) throws Exception {
  WebClient wc = WebClient.create("http://localhost:" + getPort() + baseAddress + "/books/cancel");
  Response r = wc.get();
  assertEquals(503, r.getStatus());
  String retryAfter = r.getHeaderString(HttpHeaders.RETRY_AFTER);
  assertNotNull(retryAfter);
  assertEquals("10", retryAfter);
}

代码示例来源: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

@Test
public void testGetCustomBookResponse() {
  String address = "http://localhost:" + PORT + "/bookstore/customresponse";
  WebClient wc = WebClient.create(address);
  Response r = wc.accept("application/xml").get(Response.class);
  Book book = r.readEntity(Book.class);
  assertEquals(222L, book.getId());
  assertEquals("OK", r.getHeaderString("customresponse"));
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBookLowCaseHeader() throws Exception {
  WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/booksecho3");
  wc.type("text/plain").accept("text/plain").header("CustomHeader", "custom");
  String name = wc.post("book", String.class);
  assertEquals("book", name);
  assertEquals("custom", wc.getResponse().getHeaderString("CustomHeader"));
}
@Test

代码示例来源:origin: apache/cxf

@Test
public void testPostBookNewMediaType() {
  String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
  WebClient wc = createWebClientPost(address);
  wc.header("newmediatype", "application/v1+xml");
  Book book = wc.post(new Book("Book", 126L), Book.class);
  assertEquals(124L, book.getId());
  validatePostResponse(wc, false, false);
  assertEquals("application/v1+xml", wc.getResponse().getHeaderString("newmediatypeused"));
}

相关文章