com.sun.jersey.api.representation.Form form = new Form(); form.putSingle("j_username", username); form.putSingle("j_password", password);
UriBuilder ub = request.getRequestUriBuilder(); Form f = request.getFormParameters(); for (Map.Entry<String, List<String>> param : f.entrySet()) { ub.queryParam(param.getKey(), param.getValue().toArray());
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; }
/** * 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); }
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 String getFormParameterValue(String field) { if (form==null) form = containerRequest.getFormParameters(); return form.getFirst(field); } }
@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); }
/** * 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); }
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."); } } } }
String token = response.getFirst(OAuthParameters.TOKEN); parameters.token(token); secrets.tokenSecret(response.getFirst(OAuthParameters.TOKEN_SECRET)); state = State.REQUEST_TOKEN; parameters.verifier(handler.authorize(getAuthorizationUri())); String token = response.getFirst(OAuthParameters.TOKEN); String secret = response.getFirst(OAuthParameters.TOKEN_SECRET); if (token == null) { throw new UnauthorizedRequestException(parameters, null);
@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(); } }
@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 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 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."); } } } }
UriBuilder ub = request.getRequestUriBuilder(); Form f = request.getFormParameters(); for (Map.Entry<String, List<String>> param : f.entrySet()) { ub.queryParam(param.getKey(), param.getValue().toArray());
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);
@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); }
/** * {@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(); } }
UriBuilder ub = request.getRequestUriBuilder(); Form f = request.getFormParameters(); for (Map.Entry<String, List<String>> param : f.entrySet()) { ub.queryParam(param.getKey(), param.getValue().toArray());
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); }