List of usage examples for com.google.common.net MediaType ANY_TYPE
MediaType ANY_TYPE
To view the source code for com.google.common.net MediaType ANY_TYPE.
Click Source Link
From source file:com.mastfrog.acteur.ActeurFactory.java
/** * Creates an Acteur which will read the request body, construct an object * from it, and include it for injection into later Acteurs in the chain. * * @param <T>// w ww.j av a 2s . c o m * @param type The object type * @return An acteur */ public <T> Acteur injectRequestBodyAsJSON(final Class<T> type) { @Description("Injects the body as a specific type") class InjectBody extends Acteur { @Override public com.mastfrog.acteur.State getState() { final ContentConverter converter = deps.getInstance(ContentConverter.class); HttpEvent evt = deps.getInstance(HttpEvent.class); try { MediaType mt = evt.getHeader(Headers.CONTENT_TYPE); if (mt == null) { mt = MediaType.ANY_TYPE; } try { T obj = converter.readObject(evt.getContent(), mt, type); return new ConsumedLockedState(obj); } catch (InvalidInputException e) { List<String> pblms = new LinkedList<>(); for (Problem p : e.getProblems()) { pblms.add(p.getMessage()); } return new RespondWith(Err.badRequest("Invalid data").put("problems", pblms)); } } catch (IOException ex) { Logger.getLogger(ActeurFactory.class.getName()).log(Level.SEVERE, null, ex); return new RespondWith(Err.badRequest("Bad or no JSON\n" + stackTrace(ex))); } } @Override public void describeYourself(Map<String, Object> into) { into.put("Expects JSON Request Body", true); } } return new InjectBody(); }
From source file:org.apache.aurora.scheduler.http.ServletModule.java
private MediaType getMediaType(String filePath) { if (filePath.endsWith(".png")) { return MediaType.PNG; } else if (filePath.endsWith(".js")) { return MediaType.JAVASCRIPT_UTF_8; } else if (filePath.endsWith(".html")) { return MediaType.HTML_UTF_8; } else if (filePath.endsWith(".css")) { return MediaType.CSS_UTF_8; } else if (filePath.endsWith(".svg")) { return MediaType.SVG_UTF_8; } else if (filePath.endsWith(".ttf") || filePath.endsWith(".eot") || filePath.endsWith(".woff")) { // MediaType doesn't have any mime types for fonts. Instead of magic strings, we let the // browser interpret the mime type and modern browsers can do this well. return MediaType.ANY_TYPE; } else {/* ww w .j a v a 2 s . c o m*/ throw new IllegalArgumentException("Could not determine media type for " + filePath); } }