org.apache.cxf.jaxrs.client.WebClient.form()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(96)

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

WebClient.form介绍

[英]Posts form data
[中]发布表单数据

代码示例

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

/**
 * Detects the content's language using the Lingo24 API.
 * @param content the <code>String</code> content to be used for detection
 * @return the language detected or <code>null</code> if detection failed
 */
private String detect(String content) {
  String language = null;
  if (!isAvailable) {
    return language;
  }
  Form form = new Form();
  form.param("user_key", userKey);
  form.param("q", content);
  Response response = client.accept(MediaType.APPLICATION_JSON).form(form);
  String json = response.readEntity(String.class);
  JsonElement element = new JsonParser().parse(json);
  if (element.getAsJsonObject().get("success") != null &&
      element.getAsJsonObject().get("success").getAsString().equals("true")) {
    language = element.getAsJsonObject().get("lang").getAsString();
  }
  return language;
}

代码示例来源:origin: org.apache.tika/tika-langdetect

/**
 * Detects the content's language using the Lingo24 API.
 * @param content the <code>String</code> content to be used for detection
 * @return the language detected or <code>null</code> if detection failed
 */
private String detect(String content) {
  String language = null;
  if (!isAvailable) {
    return language;
  }
  Form form = new Form();
  form.param("user_key", userKey);
  form.param("q", content);
  Response response = client.accept(MediaType.APPLICATION_JSON).form(form);
  String json = response.readEntity(String.class);
  JsonElement element = new JsonParser().parse(json);
  if (element.getAsJsonObject().get("success") != null &&
      element.getAsJsonObject().get("success").getAsString().equals("true")) {
    language = element.getAsJsonObject().get("lang").getAsString();
  }
  return language;
}

代码示例来源:origin: Talend/tesb-rt-se

private void updateAndGetUserCalendar(int hour, String event) {
  WebClient client = createClient("http://localhost:" + port + "/services/social/accounts/calendar", 
      "barry@social.com", "1234");
  Form form = new Form().param("hour", Integer.toString(hour)).param("event", event);
  client.form(form);
  printUserCalendar();
}

代码示例来源:origin: Talend/tesb-rt-se

private void updateAndGetUserCalendar(int hour, String event) {
  WebClient client = createClient("http://localhost:" + port + "/services/social/accounts/calendar", 
      "barry@social.com", "1234");
  Form form = new Form().param("hour", Integer.toString(hour)).param("event", event);
  client.form(form);
  printUserCalendar();
}

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

public UserInfo getUserInfo(ClientAccessToken at, IdToken idToken, Consumer client) {
  if (!sendTokenAsFormParameter) {
    OAuthClientUtils.setAuthorizationHeader(profileClient, at);
    if (getUserInfoFromJwt) {
      String jwt = profileClient.get(String.class);
      return getUserInfoFromJwt(jwt, idToken, client);
    }
    UserInfo profile = profileClient.get(UserInfo.class);
    validateUserInfo(profile, idToken, client);
    return profile;
  }
  Form form = new Form().param("access_token", at.getTokenKey());
  if (getUserInfoFromJwt) {
    String jwt = profileClient.form(form).readEntity(String.class);
    return getUserInfoFromJwt(jwt, idToken, client);
  }
  UserInfo profile = profileClient.form(form).readEntity(UserInfo.class);
  validateUserInfo(profile, idToken, client);
  return profile;
}
public UserInfo getUserInfoFromJwt(String profileJwtToken,

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-sso-oidc

public UserInfo getUserInfo(ClientAccessToken at, IdToken idToken, Consumer client) {
  if (!sendTokenAsFormParameter) {
    OAuthClientUtils.setAuthorizationHeader(profileClient, at);
    if (getUserInfoFromJwt) {
      String jwt = profileClient.get(String.class);
      return getUserInfoFromJwt(jwt, idToken, client);
    }
    UserInfo profile = profileClient.get(UserInfo.class);
    validateUserInfo(profile, idToken, client);
    return profile;
  }
  Form form = new Form().param("access_token", at.getTokenKey());
  if (getUserInfoFromJwt) {
    String jwt = profileClient.form(form).readEntity(String.class);
    return getUserInfoFromJwt(jwt, idToken, client);
  }
  UserInfo profile = profileClient.form(form).readEntity(UserInfo.class);
  validateUserInfo(profile, idToken, client);
  return profile;
}
public UserInfo getUserInfoFromJwt(String profileJwtToken,

代码示例来源:origin: Talend/tesb-rt-se

public void reserveTable() throws Exception {
  WebClient rs = createClient("http://localhost:" + port + "/services/reservations/reserve/table", 
      "barry@restaurant.com", "5678");
  Response r = rs.form(new Form().param("name", "Barry")
                  .param("phone", "12345678")
                  .param("hour", "7"));
    authorizeClient.header("Cookie", (String)authenticityCookie);
  Response r2 = authorizeClient.form(authorizationResult);

代码示例来源:origin: Talend/tesb-rt-se

public void reserveTable() throws Exception {
  WebClient rs = createClient("http://localhost:" + port + "/services/reservations/reserve/table", 
      "barry@restaurant.com", "5678");
  Response r = rs.form(new Form().param("name", "Barry")
                  .param("phone", "12345678")
                  .param("hour", "7"));
    authorizeClient.header("Cookie", (String)authenticityCookie);
  Response r2 = authorizeClient.form(authorizationResult);

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

@Test
public void testPostEmptyForm() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/emptyform";
  WebClient wc = WebClient.create(address);
  Response r = wc.form(new Form());
  assertEquals("empty form", r.readEntity(String.class));
}
@Test

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

@Test
public void testTooManyFormParams() throws Exception {
  String endpointAddress =
    "http://localhost:" + PORT + "/the/thebooks9/depth-form";
  WebClient wc = WebClient.create(endpointAddress);
  Response r = wc.form(new Form().param("a", "b"));
  assertEquals(204, r.getStatus());
  r = wc.form(new Form().param("a", "b").param("c", "b"));
  assertEquals(413, r.getStatus());
}

代码示例来源:origin: Talend/tesb-rt-se

public void registerClientApplication() throws Exception {
  WebClient rs = WebClient.create("http://localhost:" + port + "/services/oauth/registerProvider");
  WebClient.getConfig(rs).getHttpConduit().getClient().setReceiveTimeout(10000000L);
  rs.form(new Form().param("appName", "Restaurant Reservations")
           .param("appURI", "http://localhost:" + port + "/services/reservations/reserve"));
}

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

@Test
public void testGetBookWebClientForm() throws Exception {
  String baseAddress = "http://localhost:" + PORT
    + "/test/services/rest/bookstore/books/679/subresource3";
  WebClient wc = WebClient.create(baseAddress);
  MultivaluedMap<String, Object> map = new MetadataMap<>();
  map.putSingle("id", "679");
  map.add("name", "CXF in Action - ");
  map.add("name", "679");
  Book b = readBook((InputStream)wc.accept("application/xml")
           .form(map).getEntity());
  assertEquals(679, b.getId());
  assertEquals("CXF in Action - 679", b.getName());
}

代码示例来源:origin: Talend/tesb-rt-se

public void registerClientApplication() throws Exception {
  WebClient rs = WebClient.create("http://localhost:" + port + "/services/oauth/registerProvider");
  WebClient.getConfig(rs).getHttpConduit().getClient().setReceiveTimeout(10000000L);
  rs.form(new Form().param("appName", "Restaurant Reservations")
           .param("appURI", "http://localhost:" + port + "/services/reservations/reserve")
           .param("appRedirectURI", "http://localhost:" + port + "/services/reservations/reserve/complete")
           );
}

代码示例来源:origin: Talend/tesb-rt-se

public void createUserAccount() throws Exception {
  WebClient rs = WebClient.create("http://localhost:" + port + "/services/social/registerUser");
  WebClient.getConfig(rs).getHttpConduit().getClient().setReceiveTimeout(10000000L);
  rs.form(new Form().param("user", "barry@social.com").param("password", "1234"));
  
  printUserCalendar();
}

代码示例来源:origin: Talend/tesb-rt-se

public void createUserAccount() throws Exception {
  WebClient rs = WebClient.create("http://localhost:" + port + "/services/register/registerUser");
  WebClient.getConfig(rs).getHttpConduit().getClient().setReceiveTimeout(10000000L);
  rs.form(new Form().param("user", "barry@social.com").param("password", "1234"));
  
  printUserCalendar();
}

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

private void doTestEchoBookForm(String address) throws Exception {
  WebClient wc = WebClient.create(address);
  WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
  Book b =
    wc.form(new Form().param("name", "CXFForm").param("id", "125"))
      .readEntity(Book.class);
  assertEquals("CXFForm", b.getName());
  assertEquals(125L, b.getId());
}
@Test

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

@Test
public void testBookFromForm() throws Exception {
  WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstorestorage/bookforms",
                  "foo", "bar", null);
  wc.accept("application/xml");
  Response r = wc.form(new Form().param("name", "CXF Rocks").param("id", "123"));
  Book b = readBook((InputStream)r.getEntity());
  assertEquals("CXF Rocks", b.getName());
  assertEquals(123L, b.getId());
}

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

@Test
public void testGetBookSubresourceWebClientParamExtensions() throws Exception {
  WebClient client = WebClient.create("http://localhost:" + PORT + "/test/services/rest");
  client.type(MediaType.TEXT_PLAIN_TYPE).accept(MediaType.APPLICATION_XML_TYPE);
  client.path("/bookstore/books/139/subresource4/139/CXF Rocks");
  Book bean = new Book("CXF Rocks", 139L);
  Form form = new Form();
  form.param("name", "CXF Rocks").param("id", Long.toString(139L));
  Book b = readBook((InputStream)client.matrix("", bean).query("", bean).form(form).getEntity());
  assertEquals(139, b.getId());
  assertEquals("CXF Rocks", b.getName());
}

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

@Test
public void testGetBookWebClientForm2() throws Exception {
  String baseAddress = "http://localhost:" + PORT
    + "/test/services/rest/bookstore/books/679/subresource3";
  WebClient wc = WebClient.create(baseAddress);
  Form f = new Form(new MetadataMap<String, String>());
  f.param("id", "679").param("name", "CXF in Action - ")
    .param("name", "679");
  Book b = readBook((InputStream)wc.accept("application/xml")
           .form(f).getEntity());
  assertEquals(679, b.getId());
  assertEquals("CXF in Action - 679", b.getName());
}

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

@Test
@Ignore("Spring Security 3 does not preserve POSTed form parameters as HTTPServletRequest parameters")
public void testBookFromHttpRequestParameters() throws Exception {
  WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstorestorage/bookforms2",
                  "foo", "bar", null);
  WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L);
  wc.accept("application/xml");
  Response r = wc.form(new Form().param("name", "CXF Rocks").param("id", "123"));
  Book b = readBook((InputStream)r.getEntity());
  assertEquals("CXF Rocks", b.getName());
  assertEquals(123L, b.getId());
}

相关文章

WebClient类方法