public MediaType dataType() { if (textBasedMedia.contains(dataType.getTypeSubtype())) { return dataType.withClassType(String.class); } return dataType; }
@Test public void testParseBrowserRequest() { Stream<MediaType> list = MediaType.parseList("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); Iterator<MediaType> iterator = list.iterator(); assertEquals("text/html", iterator.next().getTypeSubtype()); assertEquals("application/xhtml+xml", iterator.next().getTypeSubtype()); assertEquals("application/xml", iterator.next().getTypeSubtype()); assertEquals("*/*", iterator.next().getTypeSubtype()); }
@Test public void testParseSingleAsterix() { Stream<MediaType> list = MediaType.parseList("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"); Iterator<MediaType> iterator = list.iterator(); assertEquals("text/html", iterator.next().getTypeSubtype()); assertEquals("image/gif", iterator.next().getTypeSubtype()); assertEquals("image/jpeg", iterator.next().getTypeSubtype()); assertEquals("*/*", iterator.next().getTypeSubtype()); }
public Object convertToRequestType(Object obj, MediaType objType, MediaType requestType) { if (obj == null) return null; if (requestType.equals(MediaType.MATCH_ALL)) return obj; // Older HR clients do not send request type and assume the script metadata type is the output type MediaType outputFormat = requestType.match(MediaType.APPLICATION_UNKNOWN) ? objType : requestType; OutputFormatter outputFormatter = formatterByMediaType.get(outputFormat.getTypeSubtype()); if (obj instanceof Collection) { if (outputFormatter != null) { return outputFormatter.formatCollection((Collection<?>) obj, objType, requestType); } } Transcoder transcoder = encoderRegistry.getTranscoder(objType, requestType); return transcoder.transcode(obj, objType, requestType); }
@Test public void testNegotiations() { Stream<MediaType> mediaTypes = MediaType.parseList("text/html; q=0.8,*/*;q=0.2,application/json"); Iterator<MediaType> iterator = mediaTypes.iterator(); MediaType preferred = iterator.next(); MediaType secondChoice = iterator.next(); MediaType everythingElse = iterator.next(); assertEquals(MediaType.APPLICATION_JSON, preferred); assertEquals("text/html", secondChoice.getTypeSubtype()); assertEquals("*/*", everythingElse.getTypeSubtype()); }
public CacheInfo getCacheInfo(AdvancedCache<byte[], byte[]> cache, HotRodHeader header) { // Fetching persistence manager would require security action, and would be too expensive CacheInfo info = cacheInfo.get(cache.getName() + header.getKeyMediaType().getTypeSubtype() + header.getValueMediaType().getTypeSubtype()); if (info == null) { AdvancedCache<byte[], byte[]> localNonBlocking = SecurityActions.anonymizeSecureCache(cache) .noFlags().withFlags(LOCAL_NON_BLOCKING_GET); if (cache.getStatus() != ComponentStatus.RUNNING) { // stay on the safe side return new CacheInfo(localNonBlocking, true, true, true); } ComponentRegistry cr = SecurityActions.getCacheComponentRegistry(cache); PersistenceManager pm = cr.getComponent(PersistenceManager.class); boolean hasIndexing = SecurityActions.getCacheConfiguration(cache).indexing().index().isEnabled(); CacheNotifierImpl cacheNotifier = (CacheNotifierImpl) cr.getComponent(CacheNotifier.class); info = new CacheInfo(localNonBlocking, pm.isEnabled(), hasIndexing, hasSyncListener(cacheNotifier)); cacheInfo.put(cache.getName() + header.getKeyMediaType().getTypeSubtype() + header.getValueMediaType().getTypeSubtype(), info); } return info; }