@Test public void testGetIdAsStringInvalidAgent() throws Exception { when(worker.getId(AGENT)).thenThrow(new InvalidUserAgentError()); try { resources.client().target("/").request(MediaType.TEXT_PLAIN) .header(HttpHeaders.USER_AGENT, AGENT) .get(ClientResponse.class); failBecauseExceptionWasNotThrown(BadRequestException.class); } catch (final BadRequestException e) { final ObjectMapper mapper = resources.getObjectMapper(); final String expected = mapper.writeValueAsString(AGENT_ERROR); final Response response = e.getResponse(); assertThat(response.getStatus()).isEqualTo(400); assertThat(response.readEntity(String.class)).isEqualTo(expected); } verify(worker).getId(AGENT); }
public long getId(final String agent) { try { return worker.getId(agent); } catch (final InvalidUserAgentError e) { LOGGER.error("Invalid user agent ({})", agent); throw new SnowizardException(Response.Status.BAD_REQUEST, "Invalid User-Agent header", e); } catch (final InvalidSystemClock e) { LOGGER.error("Invalid system clock", e); throw new SnowizardException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage(), e); } }
IdResource { public long getId(final String agent) { try { return worker.getId(agent); } catch (final InvalidUserAgentError e) { LOGGER.error("Invalid user agent ({})", agent); throw new SnowizardException(Response.Status.BAD_REQUEST, "Invalid User-Agent header", e); } catch (final InvalidSystemClock e) { LOGGER.error("Invalid system clock", e); throw new SnowizardException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage(), e); } } }
IdResource { public long getId(final String agent) { try { return worker.getId(agent); } catch (final InvalidUserAgentError e) { LOGGER.error("Invalid user agent ({})", agent); throw new SnowizardException(Response.Status.BAD_REQUEST, "Invalid User-Agent header", e); } catch (final InvalidSystemClock e) { LOGGER.error("Invalid system clock", e); throw new SnowizardException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage(), e); } } IdResource(final IdWorker worker); }
IdResource { public long getId(final String agent) { try { return worker.getId(agent); } catch (final InvalidUserAgentError e) { LOGGER.error("Invalid user agent ({})", agent); throw new SnowizardException(Response.Status.BAD_REQUEST, "Invalid User-Agent header", e); } catch (final InvalidSystemClock e) { LOGGER.error("Invalid system clock", e); throw new SnowizardException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage(), e); } } IdResource(final IdWorker worker); long getId(final String agent); @GET @Timed @Produces(MediaType.TEXT_PLAIN) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) String getIdAsString(
            @HeaderParam(HttpHeaders.USER_AGENT) final String agent); @GET @Timed @JSONP(callback = "callback", queryParam = "callback") @Produces({ MediaType.APPLICATION_JSON, MediaTypeAdditional.APPLICATION_JAVASCRIPT }) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) Id getIdAsJSON(
            @HeaderParam(HttpHeaders.USER_AGENT) final String agent); @GET @Timed @Produces(ProtocolBufferMediaType.APPLICATION_PROTOBUF) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) SnowizardResponse getIdAsProtobuf(
            @HeaderParam(HttpHeaders.USER_AGENT) final String agent,
            @QueryParam("count") final Optional<IntParam> count); }
IdResource { public long getId(final String agent) { try { return worker.getId(agent); } catch (final InvalidUserAgentError e) { LOGGER.error("Invalid user agent ({})", agent); throw new SnowizardException(Response.Status.BAD_REQUEST, "Invalid User-Agent header", e); } catch (final InvalidSystemClock e) { LOGGER.error("Invalid system clock", e); throw new SnowizardException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage(), e); } } IdResource(final IdWorker worker); long getId(final String agent); @GET @Timed @Produces(MediaType.TEXT_PLAIN) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) String getIdAsString(
            @HeaderParam(HttpHeaders.USER_AGENT) final String agent); @GET @Timed @JSONP(callback = "callback", queryParam = "callback") @Produces({ MediaType.APPLICATION_JSON, MediaTypeAdditional.APPLICATION_JAVASCRIPT }) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) Id getIdAsJSON(
            @HeaderParam(HttpHeaders.USER_AGENT) final String agent); @GET @Timed @Produces(ProtocolBufferMediaType.APPLICATION_PROTOBUF) @CacheControl(mustRevalidate = true, noCache = true, noStore = true) SnowizardResponse getIdAsProtobuf(
            @HeaderParam(HttpHeaders.USER_AGENT) final String agent,
            @QueryParam("count") final Optional<IntParam> count);  }