org.springframework.boot.configurationprocessor.json.JSONException Java Examples

The following examples show how to use org.springframework.boot.configurationprocessor.json.JSONException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyEnrichAndReformatFnTest.java    From hazelcast-jet-demos with Apache License 2.0 5 votes vote down vote up
@Test
public void json_parse() throws JSONException {
	long offset = 789;
	long timestampToUse = 987;
	String input = "123,456," + offset;
	
	String output = myEnrichAndReformatFn._makeJson(input, timestampToUse);
	
	log.info("{} -> {}", input, output);
	
	assertThat("output", output, not(nullValue()));
	
	JSONObject jsonObject = new JSONObject(output);
	
	String latitudeExtracted = jsonObject.getString("latitude");
	assertThat("latitude", latitudeExtracted, not(nullValue()));
	assertThat("latitude", latitudeExtracted, is(equalTo("123")));

	String longitudeExtracted = jsonObject.getString("longitude");
	assertThat("longitude", longitudeExtracted, not(nullValue()));
	assertThat("longitude", longitudeExtracted, is(equalTo("456")));
	
	String timestampExtracted = jsonObject.getString("timestamp");
	assertThat("timestamp", timestampExtracted, not(nullValue()));
	assertThat("timestamp", timestampExtracted, is(equalTo(""+timestampToUse)));
	
	assertThat("timestampToUse", timestampToUse, not(equalTo(offset)));
}
 
Example #2
Source File: CustomIndicatorController.java    From OpenLRW with Educational Community License v2.0 5 votes vote down vote up
/**
 * Set the status indicator
 *
 * @param token  JWT
 * @return       HTTP Response
 */
@RequestMapping(method = RequestMethod.POST)

public ResponseEntity<?> post(JwtAuthenticationToken token, @RequestBody String content) throws JSONException {
    UserContext userContext = (UserContext) token.getPrincipal(); // Check if user is logged
    JSONObject jsonObject = new JSONObject(content);
    String value = jsonObject.get("status").toString();
    boolean result = this.customIndicatorService.update(value);

    if (result) {
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    return new ResponseEntity<>("This status does not exist.", HttpStatus.BAD_REQUEST);
}
 
Example #3
Source File: MyFallbackProvider.java    From sophia_scaffolding with Apache License 2.0 4 votes vote down vote up
@Override
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
    return new ClientHttpResponse() {
        @Override
        public HttpStatus getStatusCode() throws IOException {
            return HttpStatus.OK;
        }

        @Override
        public int getRawStatusCode() throws IOException {
            return 200;
        }

        @Override
        public String getStatusText() throws IOException {
            return "OK";
        }

        @Override
        public void close() {

        }

        @Override
        public InputStream getBody() {
            SophiaHttpStatus resultEnum = SophiaHttpStatus.SERVER_TIMEOUT;
            String data = "";
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("code", resultEnum.getCode());
                jsonObject.put("msg", resultEnum.getMessage());
                jsonObject.put("data", data);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            data = jsonObject.toString();
            logger.error(data);
            return new ByteArrayInputStream(data.getBytes());
        }

        @Override
        public HttpHeaders getHeaders() {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            return headers;
        }
    };
}
 
Example #4
Source File: MyFallbackProvider.java    From sophia_scaffolding with Apache License 2.0 4 votes vote down vote up
@Override
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
    return new ClientHttpResponse() {
        @Override
        public HttpStatus getStatusCode() throws IOException {
            return HttpStatus.OK;
        }

        @Override
        public int getRawStatusCode() throws IOException {
            return 200;
        }

        @Override
        public String getStatusText() throws IOException {
            return "OK";
        }

        @Override
        public void close() {

        }

        @Override
        public InputStream getBody() {
            SophiaHttpStatus resultEnum = SophiaHttpStatus.SERVER_TIMEOUT;
            String data = "";
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("code", resultEnum.getCode());
                jsonObject.put("msg", resultEnum.getMessage());
                jsonObject.put("data", data);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            data = jsonObject.toString();
            logger.error(data);
            return new ByteArrayInputStream(data.getBytes());
        }

        @Override
        public HttpHeaders getHeaders() {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            return headers;
        }
    };
}
 
Example #5
Source File: MyFallbackProvider.java    From sophia_scaffolding with Apache License 2.0 4 votes vote down vote up
@Override
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
    return new ClientHttpResponse() {
        @Override
        public HttpStatus getStatusCode() throws IOException {
            return HttpStatus.OK;
        }

        @Override
        public int getRawStatusCode() throws IOException {
            return 200;
        }

        @Override
        public String getStatusText() throws IOException {
            return "OK";
        }

        @Override
        public void close() {

        }

        @Override
        public InputStream getBody() {
            SophiaHttpStatus resultEnum = SophiaHttpStatus.SERVER_TIMEOUT;
            String data = "";
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("code", resultEnum.getCode());
                jsonObject.put("msg", resultEnum.getMessage());
                jsonObject.put("data", data);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            data = jsonObject.toString();
            logger.error(data);
            return new ByteArrayInputStream(data.getBytes());
        }

        @Override
        public HttpHeaders getHeaders() {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            return headers;
        }
    };
}
 
Example #6
Source File: IndexUtils.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static long countDocuments(String indexName, ElasticsearchProperties properties) throws IOException, JSONException {
  HttpGet httpRequest = new HttpGet(("http://" + properties.getHost() + ":" + properties.getPort() + "/" + indexName + "/_count"));
  HttpClient httpClient = HttpClientBuilder.create().build();
  HttpResponse httpResponse = httpClient.execute(httpRequest);
  return new JSONObject(IOUtils.toString(httpResponse.getEntity().getContent(), Charset.defaultCharset())).getLong("count");
}