To use the following code you'll need the next dependencies:
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>{jackson-version}</version> </dependency>
Feel free to use your favorite JSON processing API.
This guide will include simple usage of REST services and the general documentation of this services can be found here.
package com.mkyong.rest.client; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class ProcessText { public static void main(String[] args) { try { URL url = new URL("http://localhost:8080/_saga/processText"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); String input = "{" + "\"q\":\"A WING FAILURE, RESULTING IN SUBSTANTIAL DAMAGE TO THE LAK-12 AIRCRAFT\"," + "\"tags\":[\"aircraft\",\"component\"]," + "\"splitRegex\": \"[\r|\n]+\"," + "\"type\": \"text\"," + "\"pretty\": true" + "}"; OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); ObjectMapper mapper = new ObjectMapper(); JsonNode actualObj = mapper.readTree(new InputStreamReader( (conn.getInputStream()))); if(actualObj != null){ if (actualObj.get("_success").getBooleanValue()) { System.out.println("================================================="); System.out.println("= GRAPH ="); System.out.println("=================================================\n\n"); System.out.println(actualObj.get("data").get("graph").getTextValue()); JsonNode nodeArray = actualObj.get("data").get("line"); final String nodeTemplate = "%s (%.2f)[pos: %s]"; List<String> nodeList = new ArrayList(); if(nodeArray.isArray()){ nodeArray.forEach(jsonNode -> { nodeList.add(String.format(nodeTemplate, jsonNode.get("matching").getTextValue(), jsonNode.get("confidence").getDoubleValue(), jsonNode.get("character").getTextValue())); }); } System.out.println("================================================="); System.out.println("= HIGHEST CONDIFIDENCE ROUTE ="); System.out.println("=================================================\n\n"); System.out.println(nodeList.stream().collect(Collectors.joining(" -> "))); } else { System.out.println("Failure"); } } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }