javax.ws.rs.client.Entity.form()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(222)

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

Entity.form介绍

[英]Create an javax.ws.rs.core.MediaType#APPLICATION_FORM_URLENCODEDform entity.
[中]创建一个javax。ws。rs.core。MediaType#应用程序_表单_URLENCODEDform实体。

代码示例

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

/**
   * Issues a registration request for this NiFi instance for the instance at the baseApiUri.
   *
   * @param baseApiUri uri to register with
   * @return response
   */
  public Response issueRegistrationRequest(String baseApiUri) {
    final URI uri = URI.create(String.format("%s/controller/users", baseApiUri));

    // set up the query params
    MultivaluedHashMap entity = new MultivaluedHashMap();
    entity.add("justification", "A Remote instance of NiFi has attempted to create a reference to this NiFi. This action must be approved first.");

    // get the resource
    return client.target(uri).request().post(Entity.form(entity));
  }
}

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

/**
 * Performs a POST using the specified url and form data.
 *
 * @param uri the uri to post to
 * @param formData the data to post
 * @return the client response of the post
 */
public Response post(URI uri, Map<String, String> formData) {
  // convert the form data
  final MultivaluedHashMap<String, String> entity = new MultivaluedHashMap();
  for (String key : formData.keySet()) {
    entity.add(key, formData.get(key));
  }
  // get the resource
  Invocation.Builder builder = client.target(uri).request().accept(MediaType.APPLICATION_JSON);
  // get the resource
  return builder.post(Entity.form(entity));
}

代码示例来源:origin: oracle/helidon

private Optional<SignedJwt> getAndCacheAppTokenFromServer() {
  MultivaluedMap<String, String> formData = new MultivaluedHashMap<>();
  formData.putSingle("grant_type", "client_credentials");
  formData.putSingle("scope", "urn:opc:idm:__myscopes__");
  Response tokenResponse = tokenEndpoint
      .request()
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .post(Entity.form(formData));
  if (tokenResponse.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
    JsonObject response = tokenResponse.readEntity(JsonObject.class);
    String accessToken = response.getString(ACCESS_TOKEN_KEY);
    LOGGER.finest(() -> "Access token: " + accessToken);
    SignedJwt signedJwt = SignedJwt.parseToken(accessToken);
    this.appToken = signedJwt;
    this.appJwt = signedJwt.getJwt();
    return Optional.of(signedJwt);
  } else {
    LOGGER.severe("Failed to obtain access token for application to read groups"
               + " from IDCS. Response code: " + tokenResponse.getStatus() + ", entity: "
               + tokenResponse.readEntity(String.class));
    return Optional.empty();
  }
}

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

protected Invocation prepareResource(final String key, final List<String> text, final String sourceLanguage, final String destLanguage) {
  Invocation.Builder builder = client.target(URL).request(MediaType.APPLICATION_JSON);
  final MultivaluedHashMap entity = new MultivaluedHashMap();
  entity.put("text", text);
  entity.add("key", key);
  if ((StringUtils.isBlank(sourceLanguage))) {
    entity.add("lang", destLanguage);
  } else {
    entity.add("lang", sourceLanguage + "-" + destLanguage);
  }
  return builder.buildPost(Entity.form(entity));
}

代码示例来源:origin: traccar/traccar

form.param("geolocationRequests", String.valueOf(statistics.getGeolocationRequests()));
Context.getClient().target(url).request().async().post(Entity.form(form));

代码示例来源:origin: oracle/helidon

.post(Entity.form(formValues));

代码示例来源:origin: oracle/helidon

.accept(MediaType.APPLICATION_JSON_TYPE)
.cacheControl(CacheControl.valueOf("no-cache, no-store, must-revalidate"))
.post(Entity.form(formValues));

代码示例来源:origin: jamesagnew/hapi-fhir

@Override
public IHttpRequest createParamRequest(FhirContext theContext, Map<String, List<String>> theParams, EncodingEnum theEncoding) {
  MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>();
  for (Map.Entry<String, List<String>> nextParam : theParams.entrySet()) {
    List<String> value = nextParam.getValue();
    for (String s : value) {
      map.add(nextParam.getKey(), s);
    }
  }
  Entity<Form> entity = Entity.form(map);
  JaxRsHttpRequest retVal = createHttpRequest(entity);
   addHeadersToRequest(retVal, theEncoding, theContext);
  return retVal;
}

代码示例来源:origin: resteasy/Resteasy

@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;
}

代码示例来源:origin: hortonworks/streamline

public static <T> T postForm(WebTarget target, MultivaluedMap<String, String> form, MediaType mediaType, Class<T> clazz) {
  return target.request(mediaType).post(Entity.form(form), clazz);
}

代码示例来源:origin: paymill/paymill-java

public String post( String path, ParameterMap<String, String> params ) {
 WebTarget webResource = httpClient.target( path );
 Response response = webResource.request( MediaType.APPLICATION_JSON_TYPE ).post( Entity.form( convertMap( params ) ) );
 return response.readEntity( String.class );
}

代码示例来源:origin: paymill/paymill-java

public String put( String path, ParameterMap<String, String> params ) {
 WebTarget webResource = httpClient.target( path );
 Response response = webResource.request( MediaType.APPLICATION_JSON_TYPE ).put( Entity.form( convertMap( params ) ) );
 return response.readEntity( String.class );
}

代码示例来源:origin: org.testeditor.web/org.testeditor.web.dropwizard.xtext.testing

protected Invocation createPostWithFullText(final String url, final String fullText) {
 final Form form = new Form("fullText", fullText);
 return this.createRequest(url).buildPost(Entity.form(form));
}

代码示例来源:origin: com.eclipsesource.jaxrs/consumer

private Entity<?> getEntity( Method method, Object[] parameter ) {
 Entity<?> result = null;
 if( hasFormParameter( method ) ) {
  Form form = computeForm( method, parameter );
  result = Entity.form( form );
 } else if( hasMultiPartFormParameter( method ) ) {
  MultiPart mp = computeMultiPart( method, parameter );
  result = Entity.entity( mp, mp.getMediaType() );
 } else {
  result = determineBodyParameter( method, parameter );
 }
 return result;
}

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

@Test
public void testPutBadJobStatus()
  throws IOException {
 Response resp = target(String.format("v1/jobs/%s/%s", MockJobProxy.JOB_INSTANCE_2_NAME, MockJobProxy.JOB_INSTANCE_2_ID))
   .queryParam("status", "BADSTATUS").request().put(Entity.form(new Form()));
 assertEquals(400, resp.getStatus());
 final Map<String, String> errorMessage = objectMapper.readValue(resp.readEntity(String.class), new TypeReference<Map<String, String>>() {});
 assertTrue(errorMessage.get("message").contains("BADSTATUS"));
 resp.close();
}

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

@Test
public void testPutMissingStatus()
  throws IOException {
 Response resp = target(String.format("v1/jobs/%s/%s", MockJobProxy.JOB_INSTANCE_2_NAME, MockJobProxy.JOB_INSTANCE_2_ID)).request()
   .put(Entity.form(new Form()));
 assertEquals(400, resp.getStatus());
 final Map<String, String> errorMessage = objectMapper.readValue(resp.readEntity(String.class), new TypeReference<Map<String, String>>() {});
 assertTrue(errorMessage.get("message").contains("status"));
 resp.close();
}

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

@Test
  public void testInterceptorInvokedOnFormAndFormParamMatchesFormValue() throws Exception {
    Client client = ClientBuilder.newClient();
    String uri = "http://localhost:" + PORT + "/form";
    Form f = new Form("value", "ORIGINAL");
    Response r = client.target(uri)
              .request(MediaType.APPLICATION_FORM_URLENCODED)
              .post(Entity.form(f));

    Assert.assertEquals("MODIFIED", r.getHeaderString("FromForm"));
    Assert.assertEquals("MODIFIED", r.getHeaderString("FromFormParam"));
  }
}

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

@Test
public void testStopJob()
  throws IOException {
 Response resp = target(String.format("v1/jobs/%s/%s", MockJobProxy.JOB_INSTANCE_2_NAME, MockJobProxy.JOB_INSTANCE_2_ID))
   .queryParam("status", "stopped").request().put(Entity.form(new Form()));
 assertEquals(202, resp.getStatus());
 final Job job2 = objectMapper.readValue(resp.readEntity(String.class), Job.class);
 assertEquals(MockJobProxy.JOB_INSTANCE_2_NAME, job2.getJobName());
 assertEquals(MockJobProxy.JOB_INSTANCE_2_ID, job2.getJobId());
 assertStatusNotDefault(job2);
 resp.close();
}

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

@Test
public void testStartJob()
  throws IOException {
 Response resp = target(String.format("v1/jobs/%s/%s", MockJobProxy.JOB_INSTANCE_2_NAME, MockJobProxy.JOB_INSTANCE_2_ID))
   .queryParam("status", "started").request().put(Entity.form(new Form()));
 assertEquals(202, resp.getStatus());
 final Job job2 = objectMapper.readValue(resp.readEntity(String.class), Job.class);
 assertEquals(MockJobProxy.JOB_INSTANCE_2_NAME, job2.getJobName());
 assertEquals(MockJobProxy.JOB_INSTANCE_2_ID, job2.getJobId());
 assertStatusNotDefault(job2);
 resp.close();
}

代码示例来源:origin: org.secnod.shiro/shiro-jersey

void rememberMeUserSession() {
  WebTarget sessionResource = webTarget("session");
  Form form = new Form()
    .param("username", USER1)
    .param("password", USER1_PASSWORD)
    .param("rememberMe", "true");
  Response response = sessionResource.request().post(Entity.form(form));
  int loginStatus = response.getStatus();
  response.close();
  assertEquals(200, loginStatus);
}

相关文章