APISonar


javax.ws.rs.client.Entity.json

> javax > ws > rs > client > Entity > json
javax APIs ws APIs rs APIs client APIs Entity APIs json APIs

Example 1
public void testTypeVariableBean() throws Exception {

        String request = "{\"id\": 1}";

        Response response = target("beanController").path("typeVariableBean").request().
                accept("application/json;charset=UTF-8").post(Entity.json(request));

        System.out.println(response.readEntity(String.class));

    }
Example 2
public CompletionStage<Optional<JsonObject>> create(final JsonObject json, final SecurityContext sc) {

        return client
                .target(serviceEndpoint + "/api/backend/")
                .property(ClientSecurity.PROPERTY_CONTEXT, sc)
                .request()
                .rx()
                .post(Entity.json(json))
                .thenApply(this::processSingleEntityResponse);
    }
Example 3
public Entity<String> build() {

        final StringBuilder sb = new StringBuilder();
        sb.append("{\n")
        .append(actionParameters.entrySet().stream()
                .map(this::toJson)
                .collect(Collectors.joining(",\n")))
        .append("\n}");

        return Entity.json(sb.toString());
    }
Example 4
private Entity<Object> jsonKsqlRequest(
      final String ksql,
      final Optional<Long> previousCmdSeqNum
  ) {
    return Entity.json(new KsqlRequest(
        ksql,
        localPropertiesAsMap,
        previousCmdSeqNum.orElse(null)
    ));
  }
Example 5
private Response makePostRequest(String path, Object jsonEntity) {
    return client.target(serverAddress)
        .path(path)
        .request(MediaType.APPLICATION_JSON_TYPE)
        .post(Entity.json(jsonEntity));
  }
Example 6
public void shouldNotCreateSubscriptionWithoutTopicName() {
        // given
        operations.buildTopic("invalidGroup", "topic");

        // when
        Response response = httpClient.target(MANAGEMENT_ENDPOINT_URL + "topics/invalidGroup.topic/subscriptions")
                .request()
                .post(Entity.json("{\"name\": \"subscription\"}"));

        // then
        assertThat(response).hasStatus(Response.Status.BAD_REQUEST);
    }
Example 7
public void testDeleteMultiplePipelines() {
    Response response = target("/v1/pipelines/delete").request()
        .post(Entity.json("[\"myPipeline1\", \"myPipeline2\"]"));
    Assert.assertEquals(200, response.getStatus());
  }
Example 8
public void testPost() {
        InputStream jsonStream = IntentsResourceTest.class
                .getResourceAsStream("post-config.json");
        WebTarget wt = target();

        Response response = wt.path("network/configuration")
                .request(MediaType.APPLICATION_JSON_TYPE)
                .post(Entity.json(jsonStream));
        Assert.assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    }
Example 9
public void testCreate() {
    try {
      Response response = target("/v1/pipeline/myPipeline").queryParam("description", "my description").request()
        .put(Entity.json("abc"));
      Assert.fail("Expected exception but didn't get any");
    } catch (Exception ex) {
      // Expected
    }
  }
Example 10
public void testCreateStream() {
        String streamResourceURI = getURI() + "v1/scopes/" + scope1 + "/streams";
        Response response = addAuthHeaders(client.target(streamResourceURI).request()).buildPost(Entity.json(createStreamRequest)).invoke();
        assertEquals("Create Stream Status", expectedResult, response.getStatus());
        response.close();
    }
Example 11
public void testBasicPostQuery() {
        String jsonStr = "{ \"points\": [[1.536198,42.554851], [1.548128, 42.510071]] }";
        final Response response = app.client().target("http://localhost:8080/route").request().post(Entity.json(jsonStr));
        assertEquals(200, response.getStatus());
        JsonNode json = response.readEntity(JsonNode.class);
        JsonNode infoJson = json.get("info");
        assertFalse(infoJson.has("errors"));
        JsonNode path = json.get("paths").get(0);
        double distance = path.get("distance").asDouble();
        assertTrue("distance wasn't correct:" + distance, distance > 9000);
        assertTrue("distance wasn't correct:" + distance, distance < 9500);
    }
Example 12
public void gsonJacksonRoundtrip() {

    List<String> result = client.target(SERVER_URI)
        .path("/")
        .request(MediaType.APPLICATION_JSON_TYPE)
        .accept(MediaType.APPLICATION_JSON_TYPE)
        .post(Entity.json(Collections.singletonList(13)), new GenericType<List<String>>() {});

    check(result).isOf("a", "b", "c", "[13]");
  }
Example 13
public void addMessageNegativeDurationTest() throws Exception {
        Message m = new Message("text", Collections.singleton("test"), "cssClass", Duration.ofMinutes(1));
        setDuration(m, Duration.ofMinutes(-10));

        Response r = target("messages")
                .request()
                .post(Entity.json(m));

        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus());
    }
Example 14
public void testUpdateStream() throws ExecutionException, InterruptedException {
        String resourceURI = getURI() + "v1/scopes/" + scope1 + "/streams/stream1";

        // Test to update an existing stream
        Response response = addAuthHeaders(client.target(resourceURI).request()).buildPut(Entity.json(updateStreamRequest)).invoke();
        assertEquals("Update Stream Status", expectedResult, response.getStatus());
    }
Example 15
public void testValidationGroupsException() {
        final Response resp = resources.target("/person/blah/validation-groups-exception")
            .request()
            .post(Entity.json("{}"));
        assertThat(resp.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
        assertThat(resp.readEntity(String.class))
            .isEqualTo("{\"code\":500,\"message\":\"Parameters must have the same" +
                " validation groups in validationGroupsException\"}");
    }
Example 16
public void postInvalidPrimitiveIs422() {
        // query parameter is too short and so will fail validation
        final Response response = target("/valid/simpleEntity")
                .request().post(Entity.json("hi"));

        assertThat(response.getStatus()).isEqualTo(422);

        String ret = "{\"errors\":[\"The request body length must be between 3 and 5\"]}";
        assertThat(response.readEntity(String.class)).isEqualTo(ret);
    }
Example 17
public void testSetRole() {
        mockAdminService.setRoleSync(anyObject(), anyObject(), anyObject());
        expectLastCall();
        replay(mockAdminService);

        final WebTarget wt = target();
        final InputStream jsonStream = MetersResourceTest.class
                .getResourceAsStream("put-set-roles.json");
        final Response response = wt.path("mastership")
                                    .request().put(Entity.json(jsonStream));
        assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    }
Example 18
public void testFiredEvents() {
        Response credit = target("account").queryParam("amount", 50).request().post(Entity.json(""));
        assertEquals(204, credit.getStatus());

        Response debit = target("account").queryParam("amount", 25).request().delete();
        assertEquals(204, debit.getStatus());

        Long current = target("account").queryParam("amount", 25).request().get(Long.class);
        assertEquals(25, current.longValue());
    }
Example 19
public void testMcastRouteDelete() {
        mockMulticastRouteService.remove(anyObject());
        expectLastCall();
        replay(mockMulticastRouteService);

        WebTarget wt = target().property(
                ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
        InputStream jsonStream = MulticastRouteResourceTest.class
                .getResourceAsStream("mcastroute.json");
        wt.request().method("DELETE", Entity.json(jsonStream));
    }
Example 20
public static Response syncPost(OpenstackHaService haService,
                                    String resourcePath,
                                    String input) {

        log.debug("Sync POST request with {} on {}",
                            haService.getActiveIp().toString(), resourcePath);

        return getActiveClient(haService, resourcePath)
                .request(APPLICATION_JSON_TYPE)
                .post(Entity.json(input));
    }
Example 21
public Response post(URI uri, Object entity) {
        // get the resource
        Invocation.Builder builder = client.target(uri).request().accept(MediaType.APPLICATION_JSON);

        // perform the request
        return builder.post(Entity.json(entity));
    }
Example 22
public void renameSensor() {

        assertThat(cs.ds.sensors.get("switch1").name, is("name1"));

        String body = "{'name':'name2'}";
        Response response = commonSetup.client.target(commonSetup.basePath + "/testuser/sensors/switch1").request()
                .put(Entity.json(body));
        assertEquals(200, response.getStatus());
        body = response.readEntity(String.class);
        assertThat(body, containsString("success"));
        assertThat(body, containsString("name"));
        assertThat(cs.ds.sensors.get("switch1").name, is("name2"));
    }
Example 23
public void testJsonArray() throws Exception {
        final Response response = target("jsonArray").request(MediaType.APPLICATION_JSON).post(Entity.json(JSON_ARRAY));

        assertEquals(JSON_ARRAY, response.readEntity(JsonArray.class));
    }
Example 24
public void handlesMethodNotAllowedWithHeaders() {
        final Throwable thrown = catchThrowable(() -> target("/exception/json-mapping-exception")
            .request(MediaType.APPLICATION_JSON)
            .post(Entity.json("A"), String.class));
        assertThat(thrown).isInstanceOf(WebApplicationException.class);
        final Response resp = ((WebApplicationException) thrown).getResponse();
        assertThat(resp.getStatus()).isEqualTo(405);
        assertThat(resp.getHeaders()).contains(entry("Allow", Collections.singletonList("GET,OPTIONS")));
        assertThat(resp.readEntity(String.class)).isEqualTo("{\"code\":405,\"message\":\"HTTP 405 Method Not Allowed\"}");
    }
Example 25
public void testThatResponseValidationIsNotTriggeredForUnacceptableMediaType(Map<String, String> param, StringBuilder ret) throws Exception {
        String uri = getAddress("bookstore/books/direct");

        BookWithValidation request = new BookWithValidation("BeanVal", "1");
        int code;
        try {
            Response resp = client.target(uri).request(MediaType.APPLICATION_JSON).accept("application/xml").post(Entity.json(request));
            code = resp.getStatus();
        } catch (Exception e) {
            code = -1;
        }
        assertEquals(Status.UNSUPPORTED_MEDIA_TYPE.getStatusCode(), code);
        ret.append("OK");
    }