public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (StringUtils.isEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (StringUtils.isEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + StringUtils.join(allowedContentTypes, ", ") + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); }
public static void checkContentTypes(Set<String> allowedContentTypes, String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException( "No Content-Type specified. One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); } contentType = ContentTypes.extractMimePart(contentType); if (ContentTypes.FORBIDDEN_CONTENT_TYPES.contains(contentType)) { throw new InvalidContentTypeException( "Cannot use disallowed Content-Type " + contentType); } if (allowedContentTypes.contains(contentType)) { return; } throw new InvalidContentTypeException( "Unsupported Content-Type " + contentType + ". One of " + Joiner.on(", ").join(allowedContentTypes) + " is required"); }
/** * Extract the mime part from an Http Content-Type header */ public static String extractMimePart(String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException("No Content-Type specified."); } contentType = contentType.trim(); int separator = contentType.indexOf(';'); if (separator != -1) { contentType = contentType.substring(0, separator); } return contentType.trim().toLowerCase(); }
/** * Extract the mime part from an Http Content-Type header */ public static String extractMimePart(String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException("No Content-Type specified."); } contentType = contentType.trim(); int separator = contentType.indexOf(';'); if (separator != -1) { contentType = contentType.substring(0, separator); } return contentType.trim().toLowerCase(); }
/** * Extract the mime part from an Http Content-Type header */ public static String extractMimePart(String contentType) throws InvalidContentTypeException { if (Strings.isNullOrEmpty(contentType)) { throw new InvalidContentTypeException("No Content-Type specified."); } contentType = contentType.trim(); int separator = contentType.indexOf(';'); if (separator != -1) { contentType = contentType.substring(0, separator); } return contentType.trim().toLowerCase(); }
@Override protected void doPost(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPost(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPost(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPost(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }
@Override protected void doPost(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try { ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage())); } }