Refine search
@Override public TokenResult refreshAccessToken(final String refreshToken) { refreshTokenProperties.put(OAuth2Parameters.REFRESH_TOKEN, refreshToken); final Form form = new Form(); for (final Map.Entry<String, String> entry : refreshTokenProperties.entrySet()) { form.param(entry.getKey(), entry.getValue()); } final Response response = client.target(refreshTokenUri) .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (response.getStatus() != 200) { throw new ProcessingException(LocalizationMessages.ERROR_FLOW_REQUEST_REFRESH_TOKEN(response.getStatus())); } this.tokenResult = response.readEntity(TokenResult.class); return tokenResult; }
@Override public TokenResult finish(final String authorizationCode, final String state) { if (!this.authorizationProperties.get(OAuth2Parameters.STATE).equals(state)) { throw new IllegalArgumentException(LocalizationMessages.ERROR_FLOW_WRONG_STATE()); } accessTokenProperties.put(OAuth2Parameters.CODE, authorizationCode); final Form form = new Form(); for (final Map.Entry<String, String> entry : accessTokenProperties.entrySet()) { form.param(entry.getKey(), entry.getValue()); } final Response response = client.target(accessTokenUri) .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (response.getStatus() != 200) { throw new ProcessingException(LocalizationMessages.ERROR_FLOW_REQUEST_ACCESS_TOKEN(response.getStatus())); } this.tokenResult = response.readEntity(TokenResult.class); return tokenResult; }
@Override public boolean post(String message) { Map<String, String> payload = ImmutableMap.of( "text", message, "username", slackConfig.username(), "icon_emoji", slackConfig.emoji() ); try { Form form = new Form().param("payload", mapper.writeValueAsString(payload)); this.target .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); return true; } catch (IOException ex) { LOG.warn("Can't post message to slack", ex); return false; } }
String time = DateUtil.formatDate(statistics.getCaptureTime()); Form form = new Form(); form.param("version", Context.getAppVersion()); form.param("captureTime", time); form.param("activeUsers", String.valueOf(statistics.getActiveUsers())); form.param("activeDevices", String.valueOf(statistics.getActiveDevices())); form.param("requests", String.valueOf(statistics.getRequests()));
final Form form = new Form(); form.asMap().putAll(this.form.asMap()); final Annotation[][] paramAnns = method.getParameterAnnotations(); if (value instanceof Collection) { for (final Object v : ((Collection) value)) { form.param(((FormParam) ann).value(), v.toString()); form.param(((FormParam) ann).value(), value.toString());
Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://localhost:9998").path("resource"); Form form = new Form(); form.param("x", "foo"); form.param("y", "bar"); MyJAXBBean bean = target.request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form,MediaType.APPLICATION_FORM_URLENCODED_TYPE), MyJAXBBean.class);
/** * 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; }
@Override protected ClientInvocation apply(ClientInvocation invocation, Object object) { Form form = null; Object entity = invocation.getEntity(); if (entity != null) { if (entity instanceof Form) { form = (Form) entity; } else { throw new RuntimeException(Messages.MESSAGES.cannotSetFormParameter()); } } else { form = new Form(); invocation.setEntity(Entity.form(form)); } String value = invocation.getClientConfiguration().toString(object); form.param(paramName, value); return invocation; }
public void writeTo(OOBAuthorizationResponse obj, Class<?> c, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { Form form = new Form(new MetadataMap<String, String>()); form.param(OAuth.OAUTH_VERIFIER, obj.getVerifier()); form.param(OAuth.OAUTH_TOKEN, obj.getRequestToken()); if (obj.getState() != null) { form.param(OAuthConstants.X_OAUTH_STATE, obj.getState()); } formProvider.writeTo(form, Form.class, Form.class, anns, mt, headers, os); }