Example usage for com.fasterxml.jackson.databind.node ObjectNode toString

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode toString.

Prototype

public String toString() 

Source Link

Usage

From source file:net.bcsw.sdnwlan.web.SDNWLANResource.java

/**
 * Query virtual BNG map./*w  w  w.  j a  v a  2s  . c o m*/
 *
 * @return IP Address map
 */
@GET
@Path("list")
@Produces(MediaType.APPLICATION_JSON)
public Response accessPointGetNotification() {

    log.info("Received WLAN AccessPoint GET list request");

    SDNWLANService service = get(SDNWLANService.class);

    Iterator<AccessPoint> it = service.getAccessPoints().values().iterator();

    List<AccessPointConfig> list = Lists.newArrayList();

    list.addAll(service.getAccessPoints().values().stream().map(pt -> (AccessPointConfig) pt)
            .collect(Collectors.toList()));

    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("list", new SDNWLANAccessPointCodec().encode(list, this));

    return ok(result.toString()).build();
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStep.java

private String createRouteBody(String subdomain, String domainGuid, String spaceGuid) {
    ObjectMapper mapper = new ObjectMapper();

    ObjectNode requestBody = mapper.createObjectNode();
    requestBody.put("host", subdomain);
    requestBody.put("domain_guid", domainGuid);
    requestBody.put("space_guid", spaceGuid);

    return requestBody.toString();
}

From source file:org.onosproject.tvue.TopologyResource.java

/**
 * Returns a JSON array of all paths between the specified hosts.
 *
 * @param src source host id/*from   w  w w  . j av  a2  s .co  m*/
 * @param dst target host id
 * @return JSON array of paths
 */
@javax.ws.rs.Path("/paths/{src}/{dst}")
@GET
@Produces("application/json")
public Response paths(@PathParam("src") String src, @PathParam("dst") String dst) {
    ObjectMapper mapper = new ObjectMapper();
    PathService pathService = get(PathService.class);
    Set<Path> paths = pathService.getPaths(elementId(src), elementId(dst));

    ArrayNode pathsNode = mapper.createArrayNode();
    for (Path path : paths) {
        pathsNode.add(json(mapper, path));
    }

    // Now put the vertexes and edges into a root node and ship them off
    ObjectNode rootNode = mapper.createObjectNode();
    rootNode.set("paths", pathsNode);
    return Response.ok(rootNode.toString()).build();
}

From source file:uniko.west.reveal_restlet.TopologyActionResource.java

@Get(value = "json")
@Override/*from  www  . j  av  a  2  s.com*/
public String toString() {
    ObjectNode responseObject = new ObjectNode(JsonNodeFactory.instance);
    responseObject.put("success", this.success);
    responseObject.put("status", this.status);

    return responseObject.toString();
}

From source file:com.redhat.lightblue.rest.metadata.hystrix.GetEntityNamesCommand.java

@Override
protected String run() {
    LOGGER.debug("run:");
    Error.reset();/*from ww w  .j  a  v a  2 s. c om*/
    Error.push(getClass().getSimpleName());
    try {
        HashSet<MetadataStatus> statusSet = new HashSet<>();
        for (String x : statuses) {
            statusSet.add(MetadataParser.statusFromString(x));
        }
        String[] names = getMetadata().getEntityNames(statusSet.toArray(new MetadataStatus[statusSet.size()]));
        ObjectNode node = NODE_FACTORY.objectNode();
        ArrayNode arr = NODE_FACTORY.arrayNode();
        node.put("entities", arr);
        for (String x : names) {
            arr.add(NODE_FACTORY.textNode(x));
        }
        return node.toString();
    } catch (Error e) {
        return e.toString();
    } catch (Exception e) {
        LOGGER.error("Failure: {}", e);
        return Error.get(RestMetadataConstants.ERR_REST_ERROR, e.toString()).toString();
    }
}

From source file:com.unboundid.scim2.extension.messages.consent.ScopeTest.java

/**
 * Tests serialization of Scope objects.
 *
 * @throws Exception if an error occurs.
 *///from  ww  w .  jav a2 s  .com
@Test
public void testSerialization() throws Exception {
    String name = "testName";
    String description = "testDescription";
    String consent = Scope.CONSENT_GRANTED;

    ObjectNode objectNode = JsonUtils.getJsonNodeFactory().objectNode();
    objectNode.put("name", name);
    objectNode.put("description", description);
    objectNode.put("consent", consent);

    Scope scope1 = JsonUtils.getObjectReader().forType(Scope.class).readValue(objectNode.toString());
    Assert.assertEquals(name, scope1.getName());
    Assert.assertEquals(description, scope1.getDescription());
    Assert.assertEquals(consent, scope1.getConsent());

    Scope scope2 = JsonUtils.getObjectReader().forType(Scope.class)
            .readValue(JsonUtils.getObjectWriter().writeValueAsString(scope1));
    Assert.assertEquals(scope1, scope2);
}

From source file:test.TestFinal.java

/**
 * Send HTTPS request with Jersey//from  w  ww  .ja v a 2  s .  c o m
 * 
 * @return
 */
public static ObjectNode sendRequest(JerseyWebTarget jerseyWebTarget, Object body, String method,
        List<NameValuePair> headers) throws RuntimeException {

    ObjectNode objectNode = null;
    try {

        Invocation.Builder inBuilder = jerseyWebTarget.request();
        // if (credentail != null) {
        // //inBuilder.header("Authorization",
        // "Bearer YWMtXTzzLkX_EeSRRA0PhthlrwAAAUnqX7TBUDddVXrfAPHQyGJzZRyRKzGtw8E");
        // Token.applyAuthentication(inBuilder, credentail);
        // }

        Response response = null;
        if (METHOD_GET.equals(method)) {

            response = inBuilder.get(Response.class);

        } else if (METHOD_POST.equals(method)) {
            response = inBuilder.post(Entity.entity(body, MediaType.APPLICATION_JSON), Response.class);

        } else if (METHOD_PUT.equals(method)) {

            response = inBuilder.put(Entity.entity(body, MediaType.APPLICATION_JSON), Response.class);

        } else if (METHOD_DELETE.equals(method)) {

            response = inBuilder.delete(Response.class);

        }

        objectNode = response.readEntity(ObjectNode.class);
        objectNode.put("statusCode", response.getStatus());
        System.out.println(response.getStatus() + ":" + objectNode.toString());

    } catch (Exception e) {
        e.printStackTrace();
    }

    return objectNode;
}

From source file:org.apache.asterix.api.http.server.QueryWebInterfaceServlet.java

private void doPost(IServletResponse response) throws IOException {
    ServletUtils.setContentType(response, IServlet.ContentType.APPLICATION_JSON, IServlet.Encoding.UTF8);
    ExternalProperties externalProperties = AppContextInfo.INSTANCE.getExternalProperties();
    response.setStatus(HttpResponseStatus.OK);
    ObjectMapper om = new ObjectMapper();
    ObjectNode obj = om.createObjectNode();
    try {//from www . j ava  2s  .  com
        PrintWriter out = response.writer();
        obj.put("api_port", String.valueOf(externalProperties.getAPIServerPort()));
        out.println(obj.toString());
        return;
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failure writing response", e);
    }
    try {
        response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failure setting response status", e);
    }
}

From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java

@Test
public void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception {
    // Arrange//from   ww  w.j  ava2s .c  o m
    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Subject", "Hello");
    jsonObject.put("Message", "World");
    String payload = jsonObject.toString();

    // Act
    Object notificationRequest = new NotificationRequestConverter()
            .fromMessage(MessageBuilder.withPayload(payload).build(), null);

    // Assert
    assertTrue(NotificationRequestConverter.NotificationRequest.class.isInstance(notificationRequest));
    assertEquals("Hello",
            ((NotificationRequestConverter.NotificationRequest) notificationRequest).getSubject());
    assertEquals("World",
            ((NotificationRequestConverter.NotificationRequest) notificationRequest).getMessage());
}

From source file:org.springframework.cloud.aws.messaging.support.NotificationSubjectArgumentResolverTest.java

@Test
public void resolveArgument_withValidRequestPayload_shouldReturnNotificationSubject() throws Exception {
    // Arrange//www. j a va2 s  .c  o  m
    NotificationSubjectArgumentResolver notificationSubjectArgumentResolver = new NotificationSubjectArgumentResolver();
    Method methodWithNotificationSubjectArgument = this.getClass()
            .getDeclaredMethod("methodWithNotificationSubjectArgument", String.class);
    MethodParameter methodParameter = new MethodParameter(methodWithNotificationSubjectArgument, 0);

    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Subject", "My subject!");
    jsonObject.put("Message", "message");
    String payload = jsonObject.toString();
    Message<String> message = MessageBuilder.withPayload(payload).build();

    // Act
    Object result = notificationSubjectArgumentResolver.resolveArgument(methodParameter, message);

    // Assert
    assertTrue(String.class.isInstance(result));
    assertEquals("My subject!", result);
}