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

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

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

Entity.text介绍

[英]Create a javax.ws.rs.core.MediaType#TEXT_PLAIN entity.
[中]创建一个javax。ws。rs.core。MediaType#文本#普通实体。

代码示例

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

@Benchmark
public Response post() throws Exception {
  return client.target("foo").request().post(Entity.text("bar"));
}

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

/**
 * Send message to webapp to refresh SearcherManagers for given projects.
 * This is used for partial reindex.
 *
 * @param subFiles list of directories to refresh corresponding SearcherManagers
 * @param host the host address to receive the configuration
 */
public void signalTorefreshSearcherManagers(List<String> subFiles, String host) {
  // subFile entries start with path separator so get basename
  // to convert them to project names.
  subFiles.stream().map(proj -> new File(proj).getName()).forEach(project -> {
    Response r = ClientBuilder.newClient()
        .target(host)
        .path("api")
        .path("v1")
        .path("system")
        .path("refresh")
        .request()
        .put(Entity.text(project));
    if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
      LOGGER.log(Level.WARNING, "Could not refresh search manager for {0}", project);
    }
  });
}

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

@Benchmark
public Future<Response> asyncEntityIgnore() throws Exception {
  return client.target("foo").request().async().post(Entity.text("bar"), new InvocationCallback<Response>() {
    @Override
    public void completed(final Response response) {
      // NOOP
    }
    @Override
    public void failed(final Throwable throwable) {
      // NOOP
    }
  });
}

代码示例来源:origin: Netflix/eureka

@Override
public EurekaHttpResponse<Void> statusUpdate(String asgName, ASGStatus newStatus) {
  Response response = null;
  try {
    String urlPath = "asg/" + asgName + "/status";
    response = jerseyClient.target(serviceUrl)
        .path(urlPath)
        .queryParam("value", newStatus.name())
        .request()
        .header(PeerEurekaNode.HEADER_REPLICATION, "true")
        .put(Entity.text(""));
    return EurekaHttpResponse.status(response.getStatus());
  } finally {
    if (response != null) {
      response.close();
    }
  }
}

代码示例来源:origin: OryxProject/oryx

@Override
 Invocation makeInvocation(WebTarget target, String user, String item, String strength) {
  return target.path("/pref/" + user + "/" + item).request()
    .buildPost(Entity.text(strength));
 }
},

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

private void markProjectIndexed(Project project) {
  RuntimeEnvironment env = RuntimeEnvironment.getInstance();
  // Successfully indexed the project. The message is sent even if
  // the project's isIndexed() is true because it triggers RepositoryInfo
  // refresh.
  if (project != null) {
    // Also need to store the correct value in configuration
    // when indexer writes it to a file.
    project.setIndexed(true);
    if (env.getConfigURI() != null) {
      Response r = ClientBuilder.newClient()
          .target(env.getConfigURI())
          .path("api")
          .path("v1")
          .path("projects")
          .path(Util.URIEncode(project.getName()))
          .path("indexed")
          .request()
          .put(Entity.text(""));
      if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
        LOGGER.log(Level.WARNING, "Couldn''t notify the webapp that project {0} was indexed: {1}",
            new Object[] {project, r});
      }
    }
  }
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testNoPreference() {
 Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(),
           target("/pref/U2/I2").request().post(Entity.text("aBc!")).getStatus());
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testNoIngest() {
 Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(),
           target("/ingest").request().post(Entity.text(IngestTest.INGEST_DATA)).getStatus());
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testNoTrain() {
 Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(),
           target("/train").request().post(Entity.text(TrainTest.TRAIN_DATA)).getStatus());
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testPostWithBadItemValue() {
 Response response = target("/pref/U2/I2").request().post(Entity.text("aBc!"));
 Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testNoAdd() {
 Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(),
           target("/add").request().post(Entity.text(AddTest.ADD_DATA)).getStatus());
}

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

@Test
public void pureGsonRoundtrip() {
 List<String> result = client.target(SERVER_URI)
   .path("/")
   .request(MediaType.TEXT_PLAIN_TYPE)
   .accept(MediaType.TEXT_PLAIN_TYPE)
   .post(Entity.text(Collections.singletonList("11")), new GenericType<List<String>>() {});
 check(result).isOf("x", "y", "[11]");
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testPredictPost() {
 String prediction = target("/predict").request().post(Entity.text("A,-5,\nB,0,"))
   .readEntity(String.class);
 double expectedValue1 = (1.0 + 2.0 * 100.0) / 3.0;
 double expectedValue2 = (10.0 + 2 * 1000.0) / 3;
 Assert.assertEquals(expectedValue1 + "\n" + expectedValue2 + "\n", prediction);
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testAssignPost() {
 String prediction = target("/assign").request().post(Entity.text("-1.5,0.5\n-1,0"))
   .readEntity(String.class);
 Assert.assertEquals("4\n4\n", prediction);
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testSimpleIngest() {
 checkResponse(target("/ingest").request().post(Entity.text(INGEST_DATA)));
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testPostWithEmptyItemValue() {
 Response response = target("/pref/U2/I2").request().post(Entity.text(""));
 checkResponse(response, "U2", "I2", "1");
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testURITrain() throws Exception {
 Response response = target("/train/" + TRAIN_DATA.split("\n")[0])
   .request().post(Entity.text(""));
 Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
 List<Pair<String,String>> data = MockTopicProducer.getData();
 Assert.assertEquals(1, data.size());
 Assert.assertArrayEquals(EXPECTED_TOPIC[0], data.get(0).getSecond().split(","));
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testSimpleAdd() {
 checkResponse(target("/add").request().post(Entity.text(ADD_DATA)));
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testSimpleTrain() {
 checkResponse(target("/train").request().post(Entity.text(TRAIN_DATA)));
}

代码示例来源:origin: OryxProject/oryx

@Test
public void testURIAdd() throws Exception {
 Response response = target("/add/" + ADD_DATA.split("\n")[0]).request().post(Entity.text(""));
 Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
 List<Pair<String,String>> data = MockTopicProducer.getData();
 Assert.assertEquals(1, data.size());
 Assert.assertArrayEquals(EXPECTED_TOPIC[0], data.get(0).getSecond().split(","));
}

相关文章