本文整理汇总了Java中javax.ws.rs.core.Form类的典型用法代码示例。如果您正苦于以下问题:Java Form类的具体用法?Java Form怎么用?Java Form使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Form类属于javax.ws.rs.core包,在下文中一共展示了Form类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testResetPasswordTooShort
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testResetPasswordTooShort() throws IOException {
final User user = new User();
user.setName("Example 3");
user.setEmail("[email protected]");
user.setRoles("user");
String code = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.get(Dao.class).create(user);
code = ctx.get(Security.class).forgotPassword(user);
}
final Form form = new Form();
form.param("newPassword", "foo");
form.param("confirmNewPassword", "foo");
final Response r = target("/resetpassword/" + code).request().post(Entity.form(form));
assertNotNull(r);
assertEquals(400, r.getStatus());
assertTrue(r.getCookies().isEmpty());
}
示例2: testNewOwner
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testNewOwner() {
final Response r1 = target("/owners/new").request().get();
assertEquals(200, r1.getStatus());
assertEquals("newowner", ((View) r1.getEntity()).getTemplateName());
final Form form = new Form()
.param("name", "Barack Obama")
.param("address", "1600 Penn Ave")
.param("city", "Washington DC")
.param("telephone", "800-555-5555");
final Response r2 = target("/owners/new").request().post(Entity.form(form));
assertNotNull(r2);
assertEquals(303, r2.getStatus());
assertNotNull(r2.getHeaderString("Location"));
final Response r3 = target(r2.getHeaderString("Location")).request().get();
assertNotNull(r3);
assertEquals(200, r3.getStatus());
final View view = (View) r3.getEntity();
final Owner owner = (Owner) view.getModel().get("owner");
assertEquals("Barack Obama", owner.getName());
}
示例3: submit
import javax.ws.rs.core.Form; //导入依赖的package包/类
public AccessToken submit() throws IOException {
Form form = new Form();
form.param("assertion", assertion);
form.param("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");
Entity<Form> entity = Entity.form(form);
Response response = client.target(EINSTEIN_VISION_URL + "/v1/oauth2/token")
.request()
.post(entity);
if (!isSuccessful(response)) {
throw new IOException("Error occurred while fetching Access Token " + response);
}
return readResponseAs(response, AccessToken.class);
}
示例4: testEngineWithInjectedClientPost
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testEngineWithInjectedClientPost() {
final HttpClient httpClient = Vertx.vertx().createHttpClient(httpClientOptions);
final Client client = new ResteasyClientBuilder().httpEngine(new VertxClientEngine(httpClient))
.register(GsonMessageBodyHandler.class).build();
final Form xform = new Form();
xform.param("userName", "ca1\\\\meowmix");
xform.param("password", "mingnamulan");
xform.param("state", "authenticate");
xform.param("style", "xml");
xform.param("xsl", "none");
final JsonObject arsString = client.target("https://httpbin.org/post").request()
.post(Entity.form(xform), JsonObject.class);
assertEquals("xml", arsString.getAsJsonObject("form").get("style").getAsString());
}
示例5: testEngineWithInjectedClientPost2
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testEngineWithInjectedClientPost2() {
final ResteasyDeployment deployment = new ResteasyDeployment();
deployment.start();
final ResteasyProviderFactory providerFactory = deployment.getProviderFactory();
final HttpClient httpClient = Vertx.vertx().createHttpClient(httpClientOptions);
final Client client = new ResteasyClientBuilder()
.providerFactory(providerFactory)
.httpEngine(new VertxClientEngine(httpClient))
.register(GsonMessageBodyHandler.class)
.build();
final Form xform = new Form();
xform.param("userName", "ca1\\\\meowmix");
xform.param("password", "mingnamulan");
xform.param("state", "authenticate");
xform.param("style", "xml");
xform.param("xsl", "none");
final Response response = client.target("https://httpbin.org/post").request(MediaType.APPLICATION_JSON)
.post(Entity.form(xform), Response.class);
assertFalse(response.getStringHeaders().isEmpty());
System.out.println(response.getStringHeaders());
assertFalse(response.getHeaders().isEmpty());
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getMediaType());
assertTrue(response.hasEntity());
final JsonObject arsString = response.readEntity(JsonObject.class);
assertEquals("xml", arsString.getAsJsonObject("form").get("style").getAsString());
}
示例6: testUserWithoutPassword
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testUserWithoutPassword() throws IOException {
final User user = new User();
user.setName("Example 2");
user.setEmail("[email protected]");
user.setRoles("user");
Cookie cookie = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.get(Dao.class).create(user);
cookie = ctx.get(Security.class).loginAs(user);
}
final Form form = new Form();
form.param("csrf", cookie.getValue());
form.param("oldPassword", "my-old-password");
form.param("newPassword", "my-new-password");
form.param("confirmNewPassword", "my-new-password");
final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
assertNotNull(r);
assertEquals(400, r.getStatus());
}
示例7: testIncorrectOldPassword
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testIncorrectOldPassword() throws IOException {
final User user = new User();
user.setName("Example 3");
user.setEmail("[email protected]");
user.setRoles("user");
user.setPassword("my-old-password");
Cookie cookie = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.get(Dao.class).create(user);
cookie = ctx.get(Security.class).loginAs(user);
}
final Form form = new Form();
form.param("csrf", cookie.getValue());
form.param("oldPassword", "wrong-old-password");
form.param("newPassword", "my-new-password");
form.param("confirmNewPassword", "my-new-password");
final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
assertNotNull(r);
assertEquals(400, r.getStatus());
}
示例8: testMismatchedPasswords
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testMismatchedPasswords() throws IOException {
final User user = new User();
user.setName("Example 4");
user.setEmail("[email protected]");
user.setRoles("user");
user.setPassword("my-old-password");
Cookie cookie = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.get(Dao.class).create(user);
cookie = ctx.get(Security.class).loginAs(user);
}
final Form form = new Form();
form.param("csrf", cookie.getValue());
form.param("oldPassword", "my-old-password");
form.param("newPassword", "my-new-password");
form.param("confirmNewPassword", "different-password");
final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
assertNotNull(r);
assertEquals(400, r.getStatus());
}
示例9: testPasswordTooShort
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testPasswordTooShort() throws IOException {
final User user = new User();
user.setName("Example 5");
user.setEmail("[email protected]");
user.setRoles("user");
user.setPassword("my-old-password");
Cookie cookie = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.get(Dao.class).create(user);
cookie = ctx.get(Security.class).loginAs(user);
}
final Form form = new Form();
form.param("csrf", cookie.getValue());
form.param("oldPassword", "my-old-password");
form.param("newPassword", "foo");
form.param("confirmNewPassword", "foo");
final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
assertNotNull(r);
assertEquals(400, r.getStatus());
}
示例10: testResetPasswordMismatch
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testResetPasswordMismatch() throws IOException {
final User user = new User();
user.setName("Example 2");
user.setEmail("[email protected]");
user.setRoles("user");
String code = null;
try (MinijaxRequestContext ctx = createRequestContext()) {
ctx.get(Dao.class).create(user);
code = ctx.get(Security.class).forgotPassword(user);
}
final Form form = new Form();
form.param("newPassword", "my-new-password");
form.param("confirmNewPassword", "different-password");
final Response r = target("/resetpassword/" + code).request().post(Entity.form(form));
assertNotNull(r);
assertEquals(400, r.getStatus());
assertTrue(r.getCookies().isEmpty());
}
示例11: asForm
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Override
public Form asForm() {
final MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
for (final Part part : values.values()) {
if (part.getSubmittedFileName() != null) {
continue;
}
try {
map.add(part.getName(), IOUtils.toString(part.getInputStream(), StandardCharsets.UTF_8));
} catch (final IOException ex) {
LOG.error(ex.getMessage(), ex);
}
}
return new Form(map);
}
示例12: serializeMultipartForm
import javax.ws.rs.core.Form; //导入依赖的package包/类
public static InputStream serializeMultipartForm(final Form form) {
final String boundary = "------Boundary" + UUID.randomUUID().toString();
final StringBuilder b = new StringBuilder();
final MultivaluedMap<String, String> map = form.asMap();
for (final Entry<String, List<String>> entry : map.entrySet()) {
for (final String value : entry.getValue()) {
b.append(boundary);
b.append("\nContent-Disposition: form-data; name=\"");
b.append(entry.getKey());
b.append("\"\n\n");
b.append(value);
b.append("\n");
}
}
b.append(boundary);
return new ByteArrayInputStream(b.toString().getBytes(StandardCharsets.UTF_8));
}
示例13: getEntityInputStream
import javax.ws.rs.core.Form; //导入依赖的package包/类
private InputStream getEntityInputStream() {
if (entity == null || entity.getEntity() == null) {
return null;
}
final Object obj = entity.getEntity();
if (obj instanceof InputStream) {
return (InputStream) obj;
}
if (obj instanceof String) {
return IOUtils.toInputStream((String) obj, StandardCharsets.UTF_8);
}
if (obj instanceof Form) {
if (headers.containsKey(HttpHeaders.CONTENT_TYPE) && headers.getFirst(HttpHeaders.CONTENT_TYPE).equals(MediaType.MULTIPART_FORM_DATA)) {
return MultipartUtils.serializeMultipartForm((Form) obj);
} else {
return IOUtils.toInputStream(UrlUtils.urlEncodeMultivaluedParams(((Form) obj).asMap()), StandardCharsets.UTF_8);
}
}
throw new UnsupportedOperationException("Unknown entity type: " + obj.getClass());
}
示例14: generateClient
import javax.ws.rs.core.Form; //导入依赖的package包/类
public <T> T generateClient(Class<T> resource) {
Client clientToUse = client != null
? client
: ClientBuilder.newClient();
MultivaluedMap<String, Object> headerArg = new MultivaluedHashMap<>(headers);
WebTarget webTarget = clientToUse.target(uri);
if (apiPath != null) {
webTarget = webTarget.path(apiPath);
}
if(throwExceptionForErrors) {
webTarget.register(ClientErrorResponseFilter.class);
}
webTarget.register(RequestIdClientFilter.class);
webTarget.register(ClientNameFilter.class);
if (logging) {
webTarget.register(ClientLogFilter.class);
}
return WebResourceFactory.newResource(resource, webTarget, false, headerArg, cookies, new Form());
}
示例15: testAuthWithUser
import javax.ws.rs.core.Form; //导入依赖的package包/类
@Test
public void testAuthWithUser() throws MalformedURLException {
LOG.log(Level.INFO, "base url @{0}", base);
//get an authentication
final WebTarget targetAuth = client.target(URI.create(new URL(base, "api/auth/login").toExternalForm()));
String token;
try (Response resAuth = targetAuth.request().post(form(new Form().param("username", "user").param("password", "password")))) {
assertEquals(200, resAuth.getStatus());
token = (String) resAuth.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
LOG.log(Level.INFO, "resAuth.getHeaders().getFirst(\"Bearer\"):{0}", token);
assertTrue(token != null);
}
client.register(new JwtTokenAuthentication(token.substring(AUTHORIZATION_PREFIX.length())));
final WebTarget targetUser = client.target(URI.create(new URL(base, "api/auth/userinfo").toExternalForm()));
try (Response resUser = targetUser.request().accept(MediaType.APPLICATION_JSON_TYPE).get()) {
assertEquals(200, resUser.getStatus());
final UserInfo userInfo = resUser.readEntity(UserInfo.class);
LOG.log(Level.INFO, "get user info @{0}", userInfo);
assertTrue("user".equals(userInfo.getName()));
}
}