@Override @NotNull public final Providers providers() { this.assertNotNull( this.iproviders, "%[type]s#providers was never injected by JAX-RS" ); return this.iproviders; }
/** * Build an instance of provided class. * @param type Type of resource * @return The resource * @param <T> Type of it * @since 0.4.11 */ public <T extends BaseResource> T mock(final Class<T> type) { final T rest; try { rest = type.newInstance(); } catch (final InstantiationException ex) { throw new IllegalArgumentException(ex); } catch (final IllegalAccessException ex) { throw new IllegalArgumentException(ex); } rest.setHttpHeaders(this.resource.httpHeaders()); rest.setHttpServletRequest(this.resource.httpServletRequest()); rest.setProviders(this.resource.providers()); rest.setSecurityContext(this.resource.securityContext()); rest.setServletContext(this.resource.servletContext()); rest.setUriInfo(this.resource.uriInfo()); return rest; }
/** * Set URI Info. Should be called by JAX-RS implementation * because of {@code @Context} annotation. * @param info The info to inject */ @Context public final void setUriInfo(@NotNull final UriInfo info) { if (this.needsForwarding()) { this.uri = new ForwardedUriInfo(info, this.hdrs); } else { this.uri = info; } }
@Override public Identity identity() throws IOException { final MultivaluedMap<String, String> headers = this.resource.httpHeaders().getRequestHeaders(); Identity identity = Identity.ANONYMOUS; if (headers.containsKey(Auth.HEADER_URN) && headers.containsKey(Auth.HEADER_TOKEN)) { final URN urn = URN.create(headers.getFirst(Auth.HEADER_URN)); final User user = this.base.user(urn); if (!user.exists()) { throw new WebApplicationException( Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build() ); } final String token = headers.getFirst(Auth.HEADER_TOKEN); if (!user.token().equals(token)) { throw new WebApplicationException( Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build() ); } identity = new Identity.Simple(urn, "http", URI.create("#")); } return identity; } }
@Override @NotNull public final UriInfo uriInfo() { this.assertNotNull( this.uri, "%[type]s#uriInfo was never injected by JAX-RS" ); return this.uri; }
@Override @NotNull public final HttpServletRequest httpServletRequest() { this.assertNotNull( this.req, "%[type]s#httpRequest was never injected by JAX-RS" ); return this.req; }
/** * {@inheritDoc} * @since 0.4.7 */ @Override @NotNull public final SecurityContext securityContext() { this.assertNotNull( this.security, "%[type]s#securityContext was never injected by JAX-RS" ); return this.security; }
/** * {@inheritDoc} * @since 0.4.9 */ @Override @NotNull public final ServletContext servletContext() { this.assertNotNull( this.ctx, "%[type]s#servletContext was never injected by JAX-RS" ); return this.ctx; }
@Override @NotNull public final HttpHeaders httpHeaders() { this.assertNotNull( this.hdrs.get(), "%[type]s#httpHeaders was never injected by JAX-RS" ); return this.hdrs.get(); }