Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getSomething(final String uuid) {
- String serviceUrl = getServiceUrl();
- String path = "user/" + , uuid);
- String requestUrl = serviceUrl + path;
- String httpMethod = "GET";
- Response response = client
- .target(serviceUrl)
- .path(path)
- .request(ExtendedMediaType.APPLICATION_UTF8)
- .get();
- if (response.getStatus() == Response.Status.OK.getStatusCode()) {
- // HTTP 200
- return response.readEntity(String.class);
- } else {
- // confusing code comes here just because
- // I need to decide the type of HTTP 404...
- // trying to parse response body
- try {
- String responseBody = response.readEntity(String.class);
- ObjectMapper mapper = new ObjectMapper();
- ErrorInfo errorInfo = mapper.readValue(responseBody, ErrorInfo.class);
- // re-throw the original exception
- throw new Exception("Response error code: " + response.getInternalErrorCode());
- } catch (IOException e) {
- // this is a real HTTP 404
- throw new ServiceUnavailableError(response, requestUrl, httpMethod);
- }
- // this exception will never be thrown
- throw new Exception("UNEXPECTED ERRORS, BETTER IF YOU DO NOT SEE IT IN THE LOG");
- }
- public static String getString(final String processId, final String key) {
- String serviceUrl = getServiceUrl();
- String path = String.format("key/%s", key);
- String requestUrl = serviceUrl + path;
- String httpMethod = "GET";
- log(requestUrl);
- Response response = client
- .target(serviceUrl)
- .path(path)
- .request(ExtendedMediaType.APPLICATION_JSON_UTF8)
- .header(CustomHttpHeader.PROCESS_ID, processId)
- .get();
- if (response.getStatus() == Response.Status.OK.getStatusCode()) {
- return response.readEntity(String.class);
- } else {
- String body = response.readEntity(String.class);
- ObjectMapper mapper = new ObjectMapper();
- ErrorInfo errorInfo = mapper.readValue(body, ErrorInfo.class);
- throw new Exception("Response error code: " + response.getInternalErrorCode());
- }
- throw new AnyServerError(response, requestUrl, httpMethod);
- }
Add Comment
Please, Sign In to add comment