/** * 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; }
/** * Get page generation time, in milliseconds. * @return Page generation time */ @XmlElement public final long getMillis() { return System.currentTimeMillis() - this.home().started(); }
/** * With this {@link UriInfo}. * @param info The {@link UriInfo} object * @return This object */ public ResourceMocker withUriInfo(final UriInfo info) { Mockito.doReturn(info).when(this.resource).uriInfo(); return this; }
@Override public void render(@NotNull final BasePage<?, ?> page, @NotNull final Response.ResponseBuilder builder) { if (this.resource.httpHeaders().getCookies() .containsKey(FlashInset.COOKIE)) { final FlashInset.Flash cookie = new FlashInset.Flash( this.resource.httpHeaders().getCookies().get(FlashInset.COOKIE) ); page.append( FlashInset.bundle( cookie.level(), cookie.message(), cookie.msec() ) ); builder.cookie( new CookieBuilder(this.resource.uriInfo().getBaseUri()) .name(FlashInset.COOKIE) .build() ); } }
if (this.resource.httpHeaders().getCookies() .containsKey(AuthInset.AUTH_COOKIE)) { final String cookie = this.resource.httpHeaders().getCookies() .get(AuthInset.AUTH_COOKIE).getValue(); try { "Failed to decrypt '%s' from '%s' to '%s': %[exception]s", cookie, this.resource.httpServletRequest().getRemoteAddr(), this.resource.httpServletRequest().getRequestURI(), ex ); this, "cookie '%s' not found among %[list]s", AuthInset.AUTH_COOKIE, this.resource.httpHeaders().getCookies().keySet() );
/** * With this instance of {@link HttpHeaders}. * @param headers The instance * @return This object */ public ResourceMocker withHttpHeaders(final HttpHeaders headers) { Mockito.doReturn(headers).when(this.resource).httpHeaders(); return this; }
/** * With this instance of {@link SecurityContext}. * @param ctx The context * @return This object */ public ResourceMocker withSecurityContext(final SecurityContext ctx) { Mockito.doReturn(ctx).when(this.resource).securityContext(); return this; }
/** * With this instance of {@link Providers}. * @param providers The instance * @return This object */ public ResourceMocker withProviders(final Providers providers) { Mockito.doReturn(providers).when(this.resource).providers(); return this; }
/** * With this instance of {@link ServletContext}. * @param ctx The context * @return This object * @since 0.4.11 */ public ResourceMocker withServletContext(final ServletContext ctx) { Mockito.doReturn(ctx).when(this.resource).servletContext(); return this; }
/** * With this instance of {@link HttpServletRequests}. * @param req The instance * @return This object */ public ResourceMocker withServletRequest(final HttpServletRequest req) { Mockito.doReturn(req).when(this.resource).httpServletRequest(); return this; }
/** * Redirect URI. * @return The URI */ private URI redirectUri() { return this.resource.uriInfo().getRequestUriBuilder() .clone() .queryParam(Facebook.FLAG, "") .build(); }
@Override public Identity identity() throws IOException { final List<String> headers = this.resource.httpHeaders() .getRequestHeader(HttpHeaders.AUTHORIZATION); Identity identity = Identity.ANONYMOUS; if (headers != null && !headers.isEmpty()) { identity = this.parse(headers.get(0)); } return identity; }
/** * Get SSL or non-SSL flag. * @return The flag */ @XmlAttribute public final boolean isSsl() { return this.home().securityContext().isSecure(); }
/** * Append new element. * @param element The element to append * @return This object */ public final T append(@NotNull final Object element) { if (!element.getClass().isAnnotationPresent(XmlRootElement.class)) { throw new IllegalArgumentException( Logger.format( "class %[type]s doesn't have @XmlRootElement annotation", element ) ); } this.elements.add(element); XslResolver.class.cast( this.home().providers().getContextResolver( Marshaller.class, MediaType.APPLICATION_XML_TYPE ) ).add(element.getClass()); return (T) this; }
/** * Redirect URI. * @return The URI */ private URI redirectUri() { return this.resource.uriInfo().getRequestUriBuilder() .clone() .queryParam(Amazon.FLAG, "") .build(); }
new FlashInset.Flash( uri, message, level, System.currentTimeMillis() - this.resource.started()
/** * Redirect URI. * @return The URI */ private URI redirectUri() { return this.resource.uriInfo().getRequestUriBuilder() .clone() .queryParam(Github.FLAG, "") .build(); }
@Override public Identity identity() throws IOException { Identity identity = Identity.ANONYMOUS; final boolean authed = this.resource.uriInfo() .getQueryParameters().containsKey(Google.STATE) && this.resource.uriInfo().getQueryParameters() .getFirst(Google.STATE).equals(Google.FLAG); if (authed) { final List<String> code = this.resource.uriInfo() // @checkstyle MultipleStringLiterals (1 line) .getQueryParameters().get("code"); if (code == null || code.isEmpty()) { throw new WebApplicationException( new IllegalArgumentException( "HTTP query parameter 'code' is mandatory" ), HttpURLConnection.HTTP_BAD_REQUEST ); } identity = this.fetch(this.token(code.get(0))); } return identity; }
/** * Redirect URI. * @return The URI */ private URI redirectUri() { return this.resource.uriInfo().getRequestUriBuilder() .clone() .queryParam(LinkedIn.FLAG, "") .build(); }
@Override public Identity identity() throws IOException { Identity identity = Identity.ANONYMOUS; if (this.resource.uriInfo().getQueryParameters() .containsKey(LinkedIn.FLAG)) { final List<String> code = this.resource.uriInfo() // @checkstyle MultipleStringLiterals (1 line) .getQueryParameters().get("code"); if (code == null || code.isEmpty()) { throw new WebApplicationException( new IllegalArgumentException( "HTTP query parameter 'code' is mandatory" ), HttpURLConnection.HTTP_BAD_REQUEST ); } identity = this.fetch(this.token(code.get(0))); } return identity; }