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 * 012 * @author Vladimir Dzhuvinov 013 */ 014public class ContentTypeUtils { 015 016 017 /** 018 * Ensures the content type of an HTTP header matches an expected 019 * value. Note that this method compares only the primary type and 020 * subtype; any content type parameters, such as {@code charset}, are 021 * ignored. 022 * 023 * @param expected The expected content type. Must not be {@code null}. 024 * @param found The found content type. May be {@code null}. 025 * 026 * @throws ParseException If the found content type is {@code null} or 027 * it primary and subtype and doesn't match the 028 * expected. 029 */ 030 public static void ensureContentType(final ContentType expected, final ContentType found) 031 throws ParseException { 032 033 if (found == null) 034 throw new ParseException("Missing HTTP Content-Type header"); 035 036 if (! expected.match(found)) 037 throw new ParseException("The HTTP Content-Type header must be " + expected); 038 } 039 040 041 /** 042 * Prevents instantiation. 043 */ 044 private ContentTypeUtils() { 045 046 // do nothing 047 } 048}