Java Code Examples for org.springframework.boot.configurationprocessor.json.JSONObject#toString()

The following examples show how to use org.springframework.boot.configurationprocessor.json.JSONObject#toString() . 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: 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 2
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 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;
        }
    };
}