001package com.nimbusds.oauth2.sdk.util; 002 003 004import javax.mail.internet.ContentType; 005 006import com.nimbusds.oauth2.sdk.ParseException; 007 008 009/** 010 * Content type matching. 011 */ 012public class ContentTypeUtils { 013 014 015 /** 016 * Ensures the content type of an HTTP header matches an expected 017 * value. Note that this method compares only the primary type and 018 * subtype; any content type parameters, such as {@code charset}, are 019 * ignored. 020 * 021 * @param expected The expected content type. Must not be {@code null}. 022 * @param found The found content type. May be {@code null}. 023 * 024 * @throws ParseException If the found content type is {@code null} or 025 * it primary and subtype and doesn't match the 026 * expected. 027 */ 028 public static void ensureContentType(final ContentType expected, final ContentType found) 029 throws ParseException { 030 031 if (found == null) 032 throw new ParseException("Missing HTTP Content-Type header"); 033 034 if (! expected.match(found)) 035 throw new ParseException("The HTTP Content-Type header must be " + expected); 036 } 037 038 039 /** 040 * Prevents instantiation. 041 */ 042 private ContentTypeUtils() { 043 044 // do nothing 045 } 046}