@Test public void testParseInvalidClientException() { InputStream inputStream = getClass().getResourceAsStream("invalidClient.json"); PersonalGenomeClientException exception = converter.parseException(inputStream); assertNotNull(exception); assertTrue(exception instanceof InvalidClientException); assertEquals("error description", exception.getMessage()); }
@Override public PersonalGenomeClientException parseException(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String error = null; String errorDescription = null; while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("error".equals(field)) { error = parser.getText(); } else if ("error_description".equals(field)) { errorDescription = parser.getText(); } } if ("access_denied".equals(error)) { return new AccessDeniedException(errorDescription); } else if ("invalid_client".equals(error)) { return new InvalidClientException(errorDescription); } else if ("invalid_request".equals(error)) { return new InvalidRequestException(errorDescription); } else if ("invalid_scope".equals(error)) { return new InvalidScopeException(errorDescription); } return new PersonalGenomeClientException(errorDescription); } catch (IOException e) { logger.warn("could not parse exception", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return new PersonalGenomeClientException("unknown error"); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public PersonalGenomeClientException parseException(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String error = null; String errorDescription = null; while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("error".equals(field)) { error = parser.getText(); } else if ("error_description".equals(field)) { errorDescription = parser.getText(); } } if ("access_denied".equals(error)) { return new AccessDeniedException(errorDescription); } else if ("invalid_client".equals(error)) { return new InvalidClientException(errorDescription); } else if ("invalid_request".equals(error)) { return new InvalidRequestException(errorDescription); } else if ("invalid_scope".equals(error)) { return new InvalidScopeException(errorDescription); } return new PersonalGenomeClientException(errorDescription); } catch (IOException e) { logger.warn("could not parse exception", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return new PersonalGenomeClientException("unknown error"); } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public PersonalGenomeClientException parseException(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String error = null; String errorDescription = null; while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("error".equals(field)) { error = parser.getText(); } else if ("error_description".equals(field)) { errorDescription = parser.getText(); } } if ("access_denied".equals(error)) { return new AccessDeniedException(errorDescription); } else if ("invalid_client".equals(error)) { return new InvalidClientException(errorDescription); } else if ("invalid_request".equals(error)) { return new InvalidRequestException(errorDescription); } else if ("invalid_scope".equals(error)) { return new InvalidScopeException(errorDescription); } return new PersonalGenomeClientException(errorDescription); } catch (IOException e) { logger.warn("could not parse exception", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return new PersonalGenomeClientException("unknown error"); } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public PersonalGenomeClientException parseException(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String error = null; String errorDescription = null; while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("error".equals(field)) { error = parser.getText(); } else if ("error_description".equals(field)) { errorDescription = parser.getText(); } } if ("access_denied".equals(error)) { return new AccessDeniedException(errorDescription); } else if ("invalid_client".equals(error)) { return new InvalidClientException(errorDescription); } else if ("invalid_request".equals(error)) { return new InvalidRequestException(errorDescription); } else if ("invalid_scope".equals(error)) { return new InvalidScopeException(errorDescription); } return new PersonalGenomeClientException(errorDescription); } catch (IOException e) { logger.warn("could not parse exception", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return new PersonalGenomeClientException("unknown error"); } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public PersonalGenomeClientException parseException(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String error = null; String errorDescription = null; while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("error".equals(field)) { error = parser.getText(); } else if ("error_description".equals(field)) { errorDescription = parser.getText(); } } if ("access_denied".equals(error)) { return new AccessDeniedException(errorDescription); } else if ("invalid_client".equals(error)) { return new InvalidClientException(errorDescription); } else if ("invalid_request".equals(error)) { return new InvalidRequestException(errorDescription); } else if ("invalid_scope".equals(error)) { return new InvalidScopeException(errorDescription); } return new PersonalGenomeClientException(errorDescription); } catch (IOException e) { logger.warn("could not parse exception", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return new PersonalGenomeClientException("unknown error"); } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream);  }