com.sun.jersey.api.representation.Form form = new Form(); form.putSingle("j_username", username); form.putSingle("j_password", password);
@Override public Form getFormParameters() { if (MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, getMediaType())) { InputStream in = getEntityInputStream(); if (in.getClass() != ByteArrayInputStream.class) { // Buffer input ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { ReaderWriter.writeTo(in, byteArrayOutputStream); } catch (IOException e) { throw new IllegalArgumentException(e); } in = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); setEntityInputStream(in); } ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) in; Form f = getEntity(Form.class); byteArrayInputStream.reset(); return f; } else { return new Form(); } }
com.sun.jersey.api.representation.Form input = new Form(); input.add("client_id", "Tyler_Kevin"); input.add("client_secret", "VcwDLMGuFMLnUgqldj....."); input.add("scope", "http://api.microsofttranslator.com"); input.add("grant_type", "client_credentials"); // send HTTP POST ClientResponse response = webResource.type("application/x-www-form-urlencoded") .post(ClientResponse.class, input);
public Form readFrom( Class<Form> type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { return readFrom(new Form(), mediaType, entityStream); }
public Form readFrom( Class<Form> type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { return readFrom(new Form(), mediaType, entityStream); }
private Response serviceViaOSGIPlugin(final MultivaluedMap<String, String> form, final HttpServletRequest request, final HttpServletResponse response, final ServletContext servletContext, final ServletConfig servletConfig, final UriInfo uriInfo) throws ServletException, IOException { // form will contain form parameters, if any. Even if the request contains such parameters, it may be empty // if a filter (e.g. Shiro) has already consumed them (see kludge below) return serviceViaOSGIPlugin(request, createInputStream(request, form), form, response, servletContext, servletConfig, uriInfo); }
/** * Ping as a POST * @param text text to include * @return the response * @throws IOException on any failure */ public PingInformation pingPut(String text) throws IOException { WebResource pingResource = applicationResource(ACTION_PING); Form f = new Form(); return pingResource .type(MediaType.TEXT_PLAIN) .put(PingInformation.class, text); }
/** * Ping as a POST * @param text text to include * @return the response * @throws IOException on any failure */ public PingInformation pingPut(String text) throws IOException { WebResource pingResource = applicationResource(ACTION_PING); Form f = new Form(); return pingResource .type(MediaType.TEXT_PLAIN) .put(PingInformation.class, text); }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
private void filterFormParameters(HttpServletRequest servletRequest, ContainerRequest containerRequet) throws IOException { if (MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, containerRequet.getMediaType()) && !isEntityPresent(containerRequet)) { Form f = new Form(); Enumeration e = servletRequest.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String[] values = servletRequest.getParameterValues(name); f.put(name, Arrays.asList(values)); } if (!f.isEmpty()) { containerRequet.getProperties().put(FormDispatchProvider.FORM_PROPERTY, f); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "A servlet request, to the URI " + containerRequet.getRequestUri() + ", " + "contains form parameters in " + "the request body but the request body has been consumed " + "by the servlet or a servlet filter accessing the request " + "parameters. Only resource methods using @FormParam " + "will work as expected. Resource methods consuming the " + "request body by other means will not work as expected."); } } } }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
@Override public Form getFormParameters() { if (MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, getMediaType())) { InputStream in = getEntityInputStream(); if (in.getClass() != ByteArrayInputStream.class) { // Buffer input ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { ReaderWriter.writeTo(in, byteArrayOutputStream); } catch (IOException e) { throw new IllegalArgumentException(e); } in = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); setEntityInputStream(in); } ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) in; Form f = getEntity(Form.class); byteArrayInputStream.reset(); return f; } else { return new Form(); } }
/** * Ping as a POST * @param text text to include * @return the response * @throws IOException on any failure */ public PingInformation pingPost(String text) throws IOException { WebResource pingResource = applicationResource(ACTION_PING); Form f = new Form(); f.add("text", text); return pingResource .type(MediaType.APPLICATION_JSON_TYPE) .post(PingInformation.class, f); }
/** * Ping as a POST * @param text text to include * @return the response * @throws IOException on any failure */ public PingInformation pingPost(String text) throws IOException { WebResource pingResource = applicationResource(ACTION_PING); Form f = new Form(); f.add("text", text); return pingResource .type(MediaType.APPLICATION_JSON_TYPE) .post(PingInformation.class, f); }
/** * {@inheritDoc} */ @Override public <T> T post(Map<String, String> formParams, Class<T> t) { AhcHttpClient asyncClient = AhcHttpClient.create(createAhcConfig()); try { Form form = new Form(); for (Map.Entry<String, String> e : formParams.entrySet()) { form.add(e.getKey(), e.getValue()); } WebResource r = buildRequest(asyncClient); return headers(r, TYPE.POST, true).post(t, form); } catch (UniformInterfaceException u) { headers.put(negotiateHandler.challengedHeaderName(), negotiate(u)); return post(formParams, t); } finally { asyncClient.destroy(); } }
private String getFreshAccessToken() { LOGGER.info("About get SalesForce access token"); WebResource resource = client.resource(tokenEndPointUrl); Form form = new Form(); form.add("grant_type", "password"); form.add("client_id", clientId); form.add("client_secret", clientSecret); form.add("username", username); form.add("password", password); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, form); if (response.getStatus() == 200) { try { return response.getEntity(JSONObject.class).getString("access_token"); } catch (ClientHandlerException | UniformInterfaceException | JSONException e) { throw new RuntimeException("Unable to extract access token from response", e); } } else { throw new RuntimeException("Error getting access token from SalesForce, status code = " + response.getStatus() + ", reason = " + response.getStatusInfo().getReasonPhrase() + ", body = " + response.getEntity(String.class)); } }
private static Form messageParametersAsMap(String roomIdOrName, String from, String message, Option<Message.Format> format, Option<Message.BackgroundColor> color, Option<Boolean> notify) { final Form params = new Form(); params.putSingle("room_id", roomIdOrName); params.putSingle("from", from); params.putSingle("message", message); if (format.isDefined()) { params.putSingle("message_format", format.get().value); } if (color.isDefined()) { params.putSingle("color", color.get().value); } if (notify.isDefined()) { params.putSingle("notify", notify.get() ? "1" : "0"); } return params; }
private void insertUsers(List<String> users) { Client client = Client.create(); WebResource userResources = client.resource(server.getRootUrl()).path("resources").path("users"); // LOGGER.info("Creating new account via " + userResources); for(String user : users) { Form form = new Form(); form.putSingle("email", user); form.putSingle("name", nameForEmail(user)); form.putSingle("password", DEV_PASSWORD); form.putSingle("locale", locale); ClientResponse response = userResources.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class); if(response.getStatus() == Response.Status.CREATED.getStatusCode()) { // LOGGER.info("User " + user + " created " + response.getStatus()); } else { throw new RuntimeException("Could not create user " + user + ": " + response.getClientResponseStatus() + "\n" + response.getEntity(String.class)); } } }