org.glassfish.jersey.server.ExtendedUriInfo Java Examples
The following examples show how to use
org.glassfish.jersey.server.ExtendedUriInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpanCustomizingApplicationEventListener.java From brave with Apache License 2.0 | 6 votes |
/** * This returns the matched template as defined by a base URL and path expressions. * * <p>Matched templates are pairs of (resource path, method path) added with * {@link org.glassfish.jersey.server.internal.routing.RoutingContext#pushTemplates(UriTemplate, * UriTemplate)}. This code skips redundant slashes from either source caused by Path("/") or * Path(""). */ @Nullable static String route(ContainerRequest request) { ExtendedUriInfo uriInfo = request.getUriInfo(); List<UriTemplate> templates = uriInfo.getMatchedTemplates(); int templateCount = templates.size(); if (templateCount == 0) return ""; StringBuilder builder = null; // don't allocate unless you need it! String basePath = uriInfo.getBaseUri().getPath(); String result = null; if (!"/" .equals(basePath)) { // skip empty base paths result = basePath; } for (int i = templateCount - 1; i >= 0; i--) { String template = templates.get(i).getTemplate(); if ("/" .equals(template)) continue; // skip allocation if (builder != null) { builder.append(template); } else if (result != null) { builder = new StringBuilder(result).append(template); result = null; } else { result = template; } } return result != null ? result : builder != null ? builder.toString() : ""; }
Example #2
Source File: DefaultJerseyTagsProviderTest.java From micrometer with Apache License 2.0 | 6 votes |
private static RequestEvent event(Integer status, Exception exception, String baseUri, String... uriTemplateStrings) { Builder builder = new RequestEventImpl.Builder(); ContainerRequest containerRequest = mock(ContainerRequest.class); when(containerRequest.getMethod()).thenReturn("GET"); builder.setContainerRequest(containerRequest); ContainerResponse containerResponse = mock(ContainerResponse.class); when(containerResponse.getStatus()).thenReturn(status); builder.setContainerResponse(containerResponse); builder.setException(exception, null); ExtendedUriInfo extendedUriInfo = mock(ExtendedUriInfo.class); when(extendedUriInfo.getBaseUri()).thenReturn( URI.create("http://localhost:8080" + (baseUri == null ? "/" : baseUri))); List<UriTemplate> uriTemplates = uriTemplateStrings == null ? Collections.emptyList() : Arrays.stream(uriTemplateStrings).map(uri -> new UriTemplate(uri)) .collect(Collectors.toList()); // UriTemplate are returned in reverse order Collections.reverse(uriTemplates); when(extendedUriInfo.getMatchedTemplates()).thenReturn(uriTemplates); builder.setExtendedUriInfo(extendedUriInfo); return builder.build(Type.FINISHED); }
Example #3
Source File: SpanCustomizingApplicationEventListenerTest.java From wingtips with Apache License 2.0 | 6 votes |
private void setupUriInfoWithBasePathAndUriTemplates( ExtendedUriInfo uriInfoMock, URI basePath, String ... templateStrings ) { doReturn(basePath).when(uriInfoMock).getBaseUri(); List<UriTemplate> templates = new ArrayList<>(); if (templateStrings != null) { for (String templateString : templateStrings) { templates.add(new UriTemplate(templateString)); } } doReturn(templates).when(uriInfoMock).getMatchedTemplates(); }
Example #4
Source File: PrincipalFactoryTest.java From jersey-hmac-auth with Apache License 2.0 | 6 votes |
@Test public final void verifyProvideRequiresApiKey() { // given final ExtendedUriInfo uriInfo = mock(ExtendedUriInfo.class); final MultivaluedMap<String, String> parameterMap = ImmutableMultivaluedMap.empty(); given(uriInfo.getQueryParameters()).willReturn(parameterMap); given(request.getUriInfo()).willReturn(uriInfo); // when try { factory.provide(); // then fail("Expected 400 status code"); } catch (final BadRequestException bre) { } }
Example #5
Source File: PrincipalFactoryTest.java From jersey-hmac-auth with Apache License 2.0 | 6 votes |
@Test public final void verifyProvideGrantsAccess() throws URISyntaxException { // given final MultivaluedMap<String, String> parameterMap = new MultivaluedHashMap<String, String>(); parameterMap.putSingle("apiKey", "validApiKey"); final URI uri = new URI("https://api.example.com/path/to/resource?apiKey=validApiKey"); final ExtendedUriInfo uriInfo = mock(ExtendedUriInfo.class); given(uriInfo.getQueryParameters()).willReturn(parameterMap); given(uriInfo.getRequestUri()).willReturn(uri); given(request.getUriInfo()).willReturn(uriInfo); given(request.getHeaderString("X-Auth-Version")).willReturn("1"); given(request.getHeaderString("X-Auth-Signature")).willReturn("validSignature"); given(request.getHeaderString("X-Auth-Timestamp")).willReturn("two seconds ago"); given(request.getMethod()).willReturn("GET"); given(authenticator.authenticate(any(Credentials.class))).willReturn("principal"); // when final String result = factory.provide(); // then assertEquals("principal", result); }
Example #6
Source File: DataViewMessageBodyWriter.java From ameba with MIT License | 6 votes |
private String getTemplatePath(ExtendedUriInfo uriInfo) { StringBuilder builder = new StringBuilder(); for (UriTemplate template : uriInfo.getMatchedTemplates()) { List<String> variables = template.getTemplateVariables(); String[] args = new String[variables.size()]; for (int i = 0; i < args.length; i++) { args[i] = "{" + variables.get(i) + "}"; } String uri = template.createURI(args); if (!uri.equals("/") && !uri.equals("")) builder.insert(0, uri); } return builder.toString(); }
Example #7
Source File: TemplateHelper.java From ameba with MIT License | 5 votes |
/** * Get media types for which the {@link org.glassfish.jersey.server.mvc.spi.ResolvedViewable resolved viewable} could be * produced. * * @param containerRequest request to obtain acceptable media types. * @param extendedUriInfo uri info to obtain resource method from and its producible media types. * @param varyHeaderValue Vary header reference. * @return list of producible media types. */ public static List<MediaType> getProducibleMediaTypes(final ContainerRequest containerRequest, final ExtendedUriInfo extendedUriInfo, final Ref<String> varyHeaderValue) { final List<MediaType> producedTypes = getResourceMethodProducibleTypes(extendedUriInfo); final MediaType[] mediaTypes = producedTypes.toArray(new MediaType[producedTypes.size()]); final List<Variant> variants = VariantSelector.selectVariants(containerRequest, Variant.mediaTypes(mediaTypes) .build(), varyHeaderValue == null ? Refs.emptyRef() : varyHeaderValue); return Lists.transform(variants, variant -> MediaTypes.stripQualityParams(variant.getMediaType())); }
Example #8
Source File: ContainerRequestWrapperTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void url_derivedFromExtendedUriInfo() { ExtendedUriInfo uriInfo = mock(ExtendedUriInfo.class); when(request.getUriInfo()).thenReturn(uriInfo); when(uriInfo.getRequestUri()).thenReturn(URI.create("http://foo:8080/bar?hello=world")); assertThat(new ContainerRequestWrapper(request).url()) .isEqualTo("http://foo:8080/bar?hello=world"); }
Example #9
Source File: OptionsMethodProcessor.java From ameba with MIT License | 5 votes |
@Override public Response generate(Set<String> allowedMethods, MediaType mediaType, ExtendedUriInfo extendedUriInfo, ContainerRequestContext containerRequestContext, Response response) { Response.ResponseBuilder builder = Response.fromResponse(response); if (mediaType.isCompatible(TEXT_PLAIN_TYPE)) { return builder.entity(StringUtils.join(allowedMethods, ",")).build(); } String uri = extendedUriInfo.getMatchedModelResource().getPathPattern().getTemplate().getTemplate(); return builder.entity(new AllowedMethods(uri, allowedMethods)).build(); }
Example #10
Source File: OptionsMethodProcessor.java From ameba with MIT License | 5 votes |
/** * <p>generateRespBuilder.</p> * * @param containerRequestContext a {@link javax.ws.rs.container.ContainerRequestContext} object. * @param extendedUriInfo a {@link org.glassfish.jersey.server.ExtendedUriInfo} object. * @param mediaType a {@link javax.ws.rs.core.MediaType} object. * @param respEntityGenerators a {@link java.lang.Iterable} object. * @return a {@link javax.ws.rs.core.Response.ResponseBuilder} object. */ protected static Response.ResponseBuilder generateRespBuilder( ContainerRequestContext containerRequestContext, ExtendedUriInfo extendedUriInfo, MediaType mediaType, Iterable<OptionsResponseGenerator> respEntityGenerators) { final Set<String> allowedMethods = ModelProcessorUtil.getAllowedMethods( (extendedUriInfo.getMatchedRuntimeResources().get(0))); Response.ResponseBuilder builder = Response.ok().allow(allowedMethods); if (allowedMethods.contains(HttpPatchProperties.METHOD_NAME)) { builder.header(HttpPatchProperties.ACCEPT_PATCH_HEADER, getSupportPatchMediaTypes()); } if (mediaType != null) { builder.type(mediaType); } if (respEntityGenerators != null) { Response response = builder.build(); for (OptionsResponseGenerator generator : respEntityGenerators) { response = generator.generate(allowedMethods, mediaType, extendedUriInfo, containerRequestContext, response); } builder = Response.fromResponse(response); } return builder; }
Example #11
Source File: AssetsResource.java From ameba with MIT License | 5 votes |
@GET @Path("{file:.*}") public Response getResource(@PathParam("file") String fileName, @Context ContainerRequest request, @Context ExtendedUriInfo uriInfo) throws URISyntaxException, IOException { if (!fileName.startsWith("/")) { fileName = "/" + fileName; } URI rawUri = ((Request) request).getRawReqeustUri(); String reqPath = rawUri.getPath(); int pathFileIndex = reqPath.lastIndexOf("/"); String reqFileName = reqPath; if (pathFileIndex != -1) { reqFileName = reqPath.substring(pathFileIndex); } if (!fileName.endsWith(reqFileName)) { if (pathFileIndex != -1) { fileName = fileName.substring(0, fileName.lastIndexOf("/")) + reqFileName; } else { fileName = reqFileName; } } List<String> uris = uriInfo.getMatchedURIs(true); String mapName = uris.get(uris.size() - 1); URL url = AssetsFeature.lookupAsset(mapName, fileName); return assets(url, request); }
Example #12
Source File: TemplateModelProcessor.java From ameba with MIT License | 5 votes |
/** * Obtains a model object for a viewable. * * @param extendedUriInfo uri info to obtain last matched resource from. * @return a model object. */ private Object getModel(final ExtendedUriInfo extendedUriInfo) { final List<Object> matchedResources = extendedUriInfo.getMatchedResources(); if (resourceInstance != null) { return setModelClass(resourceInstance); } else if (matchedResources.size() > 1) { return setModelClass(matchedResources.get(1)); } else { return setModelClass(resourceContext.getResource(resourceClass)); } }
Example #13
Source File: TemplateModelProcessor.java From ameba with MIT License | 5 votes |
/** * Create a {@code TemplateModelProcessor} instance. * * @param resourceContext (injected) resource context. * @param extendedUriInfoProvider (injected) extended uri info provider. */ @Inject TemplateModelProcessor(final ResourceContext resourceContext, final Provider<ConfiguredValidator> validatorProvider, final Provider<ExtendedUriInfo> extendedUriInfoProvider) { this.resourceContext = resourceContext; this.validatorProvider = validatorProvider; this.extendedUriInfoProvider = extendedUriInfoProvider; }
Example #14
Source File: TemplateHelper.java From ameba with MIT License | 5 votes |
/** * Return a list of producible media types of the last matched resource method. * * @param extendedUriInfo uri info to obtain resource method from. * @return list of producible media types of the last matched resource method. */ private static List<MediaType> getResourceMethodProducibleTypes(final ExtendedUriInfo extendedUriInfo) { if (extendedUriInfo.getMatchedResourceMethod() != null && !extendedUriInfo.getMatchedResourceMethod().getProducedTypes().isEmpty()) { return extendedUriInfo.getMatchedResourceMethod().getProducedTypes(); } return Collections.singletonList(MediaType.WILDCARD_TYPE); }
Example #15
Source File: PrincipalFactoryTest.java From jersey-hmac-auth with Apache License 2.0 | 5 votes |
@Test public final void verifyProvideAppliesContentToSignature() throws URISyntaxException, UnsupportedEncodingException { // given final MultivaluedMap<String, String> parameterMap = new MultivaluedHashMap<String, String>(); parameterMap.putSingle("apiKey", "validApiKey"); final URI uri = new URI("https://api.example.com/path/to/resource?apiKey=validApiKey"); final ExtendedUriInfo uriInfo = mock(ExtendedUriInfo.class); given(uriInfo.getQueryParameters()).willReturn(parameterMap); given(uriInfo.getRequestUri()).willReturn(uri); given(request.getUriInfo()).willReturn(uriInfo); given(request.getHeaderString("X-Auth-Version")).willReturn("1"); given(request.getHeaderString("X-Auth-Signature")).willReturn("validSignature"); given(request.getHeaderString("X-Auth-Timestamp")).willReturn("two seconds ago"); given(request.getMethod()).willReturn("PUT"); given(request.hasEntity()).willReturn(true); given(request.getEntityStream()).willReturn(new ByteArrayInputStream("content".getBytes("UTF-8"))); given(authenticator.authenticate(any(Credentials.class))).willReturn("principal"); // when final String result = factory.provide(); // then assertEquals("principal", result); final ArgumentCaptor<Credentials> credentialsCaptor = ArgumentCaptor.forClass(Credentials.class); verify(authenticator).authenticate(credentialsCaptor.capture()); final Credentials credentials = credentialsCaptor.getValue(); assertEquals("validApiKey", credentials.getApiKey()); assertEquals("two seconds ago", credentials.getTimestamp()); assertEquals("PUT", credentials.getMethod()); assertEquals("/path/to/resource?apiKey=validApiKey", credentials.getPath()); assertEquals("content", new String(credentials.getContent(), "UTF-8")); }
Example #16
Source File: PrincipalFactoryTest.java From jersey-hmac-auth with Apache License 2.0 | 5 votes |
@Test public final void verifyProvideDeniesAccess() throws URISyntaxException { // given final MultivaluedMap<String, String> parameterMap = new MultivaluedHashMap<String, String>(); parameterMap.putSingle("apiKey", "invalidApiKey"); final URI uri = new URI("https://api.example.com/path/to/resource?apiKey=invalidApiKey"); final ExtendedUriInfo uriInfo = mock(ExtendedUriInfo.class); given(uriInfo.getQueryParameters()).willReturn(parameterMap); given(uriInfo.getRequestUri()).willReturn(uri); given(request.getUriInfo()).willReturn(uriInfo); given(request.getHeaderString("X-Auth-Version")).willReturn("1"); given(request.getHeaderString("X-Auth-Signature")).willReturn("invalidSignature"); given(request.getHeaderString("X-Auth-Timestamp")).willReturn("two days ago"); given(request.getMethod()).willReturn("POST"); given(authenticator.authenticate(any(Credentials.class))).willReturn(null); // when try { factory.provide(); // then fail("Expected 401 status code"); } catch (final NotAuthorizedException nae) { } }
Example #17
Source File: JerseyTags.java From micrometer with Apache License 2.0 | 5 votes |
private static String getMatchingPattern(RequestEvent event) { ExtendedUriInfo uriInfo = event.getUriInfo(); List<UriTemplate> templates = uriInfo.getMatchedTemplates(); StringBuilder sb = new StringBuilder(); sb.append(uriInfo.getBaseUri().getPath()); for (int i = templates.size() - 1; i >= 0; i--) { sb.append(templates.get(i).getTemplate()); } String multipleSlashCleaned = MULTIPLE_SLASH_PATTERN.matcher(sb.toString()).replaceAll("/"); if (multipleSlashCleaned.equals("/")) { return multipleSlashCleaned; } return TRAILING_SLASH_PATTERN.matcher(multipleSlashCleaned).replaceAll(""); }
Example #18
Source File: SpanCustomizingApplicationEventListenerTest.java From wingtips with Apache License 2.0 | 5 votes |
@Before public void beforeMethod() { implSpy = spy(SpanCustomizingApplicationEventListener.create()); requestEventMock = mock(RequestEvent.class); requestMock = mock(ContainerRequest.class); extendedUriInfoMock = mock(ExtendedUriInfo.class); doReturn(RequestEvent.Type.REQUEST_MATCHED).when(requestEventMock).getType(); doReturn(requestMock).when(requestEventMock).getContainerRequest(); doReturn(extendedUriInfoMock).when(requestMock).getUriInfo(); }
Example #19
Source File: SpanCustomizingApplicationEventListener.java From wingtips with Apache License 2.0 | 5 votes |
/** * This returns the matched template as defined by a base URL and path expressions. * * <p>Matched templates are pairs of (resource path, method path) added with * {@link RoutingContext#pushTemplates(UriTemplate, UriTemplate)}. * This code skips redundant slashes from either source caused by Path("/") or Path(""). */ protected String route(ContainerRequest request) { ExtendedUriInfo uriInfo = request.getUriInfo(); List<UriTemplate> templates = uriInfo.getMatchedTemplates(); int templateCount = templates.size(); if (templateCount == 0) { return ""; } StringBuilder builder = null; // don't allocate unless you need it! String basePath = uriInfo.getBaseUri().getPath(); String result = null; if (!"/".equals(basePath)) { // skip empty base paths result = basePath; } for (int i = templateCount - 1; i >= 0; i--) { String template = templates.get(i).getTemplate(); if ("/".equals(template)) { continue; // skip allocation } if (builder != null) { builder.append(template); } else if (result != null) { builder = new StringBuilder(result).append(template); result = null; } else { result = template; } } return (result != null) ? result : (builder != null) ? builder.toString() : ""; }
Example #20
Source File: JacksonSerializerMessageBodyReaderWriter.java From servicetalk with Apache License 2.0 | 4 votes |
private static boolean isSse(ContainerRequestContext requestCtx) { final ResourceMethod method = ((ExtendedUriInfo) requestCtx.getUriInfo()).getMatchedResourceMethod(); return method != null && method.isSse(); }
Example #21
Source File: AbstractMessageBodyReaderWriter.java From servicetalk with Apache License 2.0 | 4 votes |
static boolean isSse(ContainerRequestContext requestCtx) { final ResourceMethod method = ((ExtendedUriInfo) requestCtx.getUriInfo()).getMatchedResourceMethod(); return method != null && method.isSse(); }
Example #22
Source File: TracingApplicationEventListenerAdapterBenchmarks.java From brave with Apache License 2.0 | 4 votes |
@Override public ExtendedUriInfo getUriInfo() { return nestedUriInfo; }
Example #23
Source File: TracingApplicationEventListenerAdapterBenchmarks.java From brave with Apache License 2.0 | 4 votes |
@Override public ExtendedUriInfo getUriInfo() { return uriInfo; }
Example #24
Source File: RestTriggerResourceTest.java From development with Apache License 2.0 | 4 votes |
@Test public void testDefinition() throws Exception { RestTriggerResource resource = new RestTriggerResource(); RestTriggerResource.Definition definition = resource .redirectToTrigger(); DefinitionBackend backend = new DefinitionBackend(); TriggerDefinitionService service = Mockito .mock(TriggerDefinitionService.class); backend.setService(service); resource.setDefinitionBackend(backend); TriggerParameters params = new TriggerParameters(); params.setId(new Long(1L)); params.setMatch("1"); ContainerRequest request = Mockito.mock(ContainerRequest.class); Mockito.when(request.getProperty(Mockito.anyString())) .thenReturn(new Integer(CommonParams.VERSION_1)); ExtendedUriInfo uri = Mockito.mock(ExtendedUriInfo.class); Mockito.when(request.getUriInfo()).thenReturn(uri); Mockito.when(uri.getAbsolutePathBuilder()) .thenReturn(UriBuilder.fromPath("")); Response response = definition.getCollection(request, params); assertThat(response.getEntity(), IsInstanceOf.instanceOf(RepresentationCollection.class)); response = definition.getItem(request, params); assertThat(response.getEntity(), IsInstanceOf.instanceOf(DefinitionRepresentation.class)); DefinitionRepresentation content = new DefinitionRepresentation(); content.setId(new Long(1L)); content.setETag(new Long(1L)); content.setDescription("abc"); content.setSuspending(Boolean.TRUE); content.setType("REST_SERVICE"); content.setTargetURL("http://abc.de/asdf"); content.setAction("SUBSCRIBE_TO_SERVICE"); response = definition.postCollection(request, content, params); assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); response = definition.putItem(request, content, params); assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); }
Example #25
Source File: TemplateModelProcessor.java From ameba with MIT License | 4 votes |
/** * Returns a list of template names to be considered as candidates for resolving * {@link org.glassfish.jersey.server.mvc.Viewable viewable} into * {@link org.glassfish.jersey.server.mvc.spi.ResolvedViewable resolved viewable}. * <p/> * Order of template names to be resolved is as follows: * <ul> * <li>{{@value #IMPLICIT_VIEW_PATH_PARAMETER}} value</li> * <li>{@link org.glassfish.jersey.server.mvc.Template#name()}</li> * <li>last sub-resource manager path</li> * <li>index</li> * </ul> * * @param requestContext request context to obtain {@link #IMPLICIT_VIEW_PATH_PARAMETER} value from. * @return a non-empty list of template names. */ private List<String> getTemplateNames(final ContainerRequestContext requestContext) { final List<String> templateNames = Lists.newArrayList(); // Template name extracted from path param. final String pathTemplate = requestContext.getUriInfo().getPathParameters().getFirst(IMPLICIT_VIEW_PATH_PARAMETER); if (pathTemplate != null) { templateNames.add(pathTemplate); } // Annotation. if (this.templateName != null && this.templateName.length > 0) { for (String name : this.templateName) { if (StringUtils.isNotBlank(name)) { templateNames.add(name); } } } // Sub-resource path. final ExtendedUriInfo uriInfo = extendedUriInfoProvider.get(); final List<RuntimeResource> matchedRuntimeResources = uriInfo.getMatchedRuntimeResources(); if (matchedRuntimeResources.size() > 1) { // > 1 to check that we matched sub-resource final RuntimeResource lastMatchedRuntimeResource = matchedRuntimeResources.get(0); final Resource lastMatchedResource = lastMatchedRuntimeResource.getResources().get(0); String path = lastMatchedResource.getPath(); if (path != null && !IMPLICIT_VIEW_PATH_PARAMETER_TEMPLATE.equals(path)) { path = path.charAt(0) == '/' ? path.substring(1, path.length()) : path; templateNames.add(path); } } // Index. if (templateNames.isEmpty()) { templateNames.add("index"); } return templateNames; }
Example #26
Source File: JerseyGuicierModule.java From dropwizard-guicier with Apache License 2.0 | 4 votes |
@Provides @RequestScoped public ExtendedUriInfo providesExtendedUriInfo(ServiceLocator serviceLocator) { return serviceLocator.getService(ExtendedUriInfo.class); }
Example #27
Source File: PrincipalFactoryTest.java From jersey-hmac-auth with Apache License 2.0 | 4 votes |
@Test public final void verifyProvidePassesContentDownstream() throws URISyntaxException, IOException { // given final String content = "content"; final SecurityContext securityContext = mock(SecurityContext.class); final PropertiesDelegate propertiesDelegate = mock(PropertiesDelegate.class); final MultivaluedMap<String, String> parameterMap = new MultivaluedHashMap<String, String>(); parameterMap.putSingle("apiKey", "validApiKey"); final URI uri = new URI("https://api.example.com/path/to/resource?apiKey=validApiKey"); final ExtendedUriInfo uriInfo = mock(ExtendedUriInfo.class); given(uriInfo.getQueryParameters()).willReturn(parameterMap); given(uriInfo.getRequestUri()).willReturn(uri); final ContainerRequest containerRequest = new ContainerRequest(new URI("https://api.example.com"), new URI("https://api.example.com/path/to/resource?apiKey=validApiKey"), "POST", securityContext, propertiesDelegate); request = spy(containerRequest); request.setEntityStream(new ByteArrayInputStream(content.getBytes("UTF-8"))); request.header("X-Auth-Version", "1"); request.header("X-Auth-Signature", "validSignature"); request.header("X-Auth-Timestamp", "two seconds ago"); given(request.getMethod()).willReturn("POST"); given(request.getUriInfo()).willReturn(uriInfo); given(requestProvider.get()).willReturn(request); given(authenticator.authenticate(any(Credentials.class))).willReturn("principal"); // when final String result = factory.provide(); // then assertEquals("principal", result); assertTrue(request.hasEntity()); final InputStream entityStream = request.getEntityStream(); try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteStreams.copy(entityStream, outputStream); assertEquals(content, new String(outputStream.toByteArray(), "UTF-8")); } finally { entityStream.close(); } }
Example #28
Source File: OptionsMethodProcessor.java From ameba with MIT License | 2 votes |
/** * <p>generateRespBuilder.</p> * * @param extendedUriInfo a {@link org.glassfish.jersey.server.ExtendedUriInfo} object. * @param mediaType a {@link javax.ws.rs.core.MediaType} object. * @return a {@link javax.ws.rs.core.Response.ResponseBuilder} object. */ protected static Response.ResponseBuilder generateRespBuilder(ExtendedUriInfo extendedUriInfo, MediaType mediaType) { return generateRespBuilder(null, extendedUriInfo, mediaType, null); }
Example #29
Source File: OptionsResponseGenerator.java From ameba with MIT License | 2 votes |
/** * <p>generate.</p> * * @param allowedMethods a {@link java.util.Set} object. * @param mediaType a {@link javax.ws.rs.core.MediaType} object. * @param extendedUriInfo a {@link org.glassfish.jersey.server.ExtendedUriInfo} object. * @param containerRequestContext a {@link javax.ws.rs.container.ContainerRequestContext} object. * @param response a {@link javax.ws.rs.core.Response} object. * @return a {@link javax.ws.rs.core.Response} object. */ Response generate(Set<String> allowedMethods, MediaType mediaType, ExtendedUriInfo extendedUriInfo, ContainerRequestContext containerRequestContext, Response response);
Example #30
Source File: RequestEvent.java From ameba with MIT License | 2 votes |
/** * <p>getUriInfo.</p> * * @return a {@link org.glassfish.jersey.server.ExtendedUriInfo} object. */ public ExtendedUriInfo getUriInfo() { return event.getUriInfo(); }