Source:
private Optional<Result> createSession(HttpClient client, JsonObject params) throws IOException { HttpRequest request = new HttpRequest(HttpMethod.POST, "/session"); String content = params.toString(); byte[] data = content.getBytes(UTF_8); request.setHeader(CONTENT_LENGTH, String.valueOf(data.length)); request.setHeader(CONTENT_TYPE, JSON_UTF_8.toString()); request.setContent(data); HttpResponse response = client.execute(request, true); Map<?, ?> jsonBlob = null; String resultString = response.getContentString(); try { jsonBlob = new JsonToBeanConverter().convert(Map.class, resultString); } catch (ClassCastException e) { return Optional.empty(); } catch (JsonException e) { } if (jsonBlob == null) { jsonBlob = new HashMap<>(); } Object sessionId = jsonBlob.get("sessionId"); Object value = jsonBlob.get("value"); Object w3cError = jsonBlob.get("error"); Object ossStatus = jsonBlob.get("status"); Map<String, ?> capabilities = null; if (value != null && value instanceof Map) { capabilities = (Map<String, ?>) value; } else if (value != null && value instanceof Capabilities) { capabilities = ((Capabilities) capabilities).asMap(); } if (response.getStatus() == HttpURLConnection.HTTP_OK && sessionId != null && capabilities != null) { Dialect dialect = ossStatus == null ? Dialect.W3C : Dialect.OSS; return Optional.of( new Result(dialect, String.valueOf(sessionId), capabilities)); } Response tempResponse = null; if ("session not created".equals(w3cError)) { tempResponse = new Response(null); tempResponse.setStatus(SESSION_NOT_CREATED); tempResponse.setValue(jsonBlob); } else if ( ossStatus instanceof Number && ((Number) ossStatus).intValue() == SESSION_NOT_CREATED) { tempResponse = new Response(null); tempResponse.setStatus(SESSION_NOT_CREATED); tempResponse.setValue(jsonBlob); } if (tempResponse != null) { new ErrorHandler().throwIfResponseFailed(tempResponse, 0); } return Optional.empty(); }

Target:
private Optional<Result> createSession(HttpClient client, JsonObject params) throws IOException { HttpRequest request = new HttpRequest(HttpMethod.POST, "/session"); String content = params.toString(); byte[] data = content.getBytes(UTF_8); request.setHeader(CONTENT_LENGTH, String.valueOf(data.length)); request.setHeader(CONTENT_TYPE, JSON_UTF_8.toString()); request.setContent(data); HttpResponse response = client.execute(request, true); Map<?, ?> jsonBlob = new HashMap<>(); String resultString = response.getContentString(); try { jsonBlob = new JsonToBeanConverter().convert(Map.class, resultString); } catch (ClassCastException e) { return Optional.empty(); } catch (JsonException e) { } Object sessionId = jsonBlob.get("sessionId"); Object value = jsonBlob.get("value"); Object w3cError = jsonBlob.get("error"); Object ossStatus = jsonBlob.get("status"); Map<String, ?> capabilities = null; if (value != null && value instanceof Map) { capabilities = (Map<String, ?>) value; } else if (value != null && value instanceof Capabilities) { capabilities = ((Capabilities) capabilities).asMap(); } if (response.getStatus() == HttpURLConnection.HTTP_OK && sessionId != null && capabilities != null) { Dialect dialect = ossStatus == null ? Dialect.W3C : Dialect.OSS; return Optional.of( new Result(dialect, String.valueOf(sessionId), capabilities)); } Response tempResponse = null; if ("session not created".equals(w3cError)) { tempResponse = new Response(null); tempResponse.setStatus(SESSION_NOT_CREATED); tempResponse.setValue(jsonBlob); } else if ( ossStatus instanceof Number && ((Number) ossStatus).intValue() == SESSION_NOT_CREATED) { tempResponse = new Response(null); tempResponse.setStatus(SESSION_NOT_CREATED); tempResponse.setValue(jsonBlob); } if (tempResponse != null) { new ErrorHandler().throwIfResponseFailed(tempResponse, 0); } return Optional.empty(); }