All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.datalking.web.http.accept.HeaderContentNegotiationStrategy Maven / Gradle / Ivy

The newest version!
package com.github.datalking.web.http.accept;

import com.github.datalking.util.StringUtils;
import com.github.datalking.web.context.request.WebRequest;
import com.github.datalking.web.http.MediaType;

import java.util.Collections;
import java.util.List;

public class HeaderContentNegotiationStrategy implements ContentNegotiationStrategy {

    private static final String ACCEPT_HEADER = "Accept";

    public List resolveMediaTypes(WebRequest webRequest) {
        String acceptHeader = webRequest.getHeader(ACCEPT_HEADER);
        try {
            if (StringUtils.hasText(acceptHeader)) {
                List mediaTypes = MediaType.parseMediaTypes(acceptHeader);
//                MediaType.sortBySpecificityAndQuality(mediaTypes);
                return mediaTypes;
            }
        } catch (IllegalArgumentException ex) {
//            throw new HttpMediaTypeNotAcceptableException("Could not parse accept header [" + acceptHeader + "]: " + ex.getMessage());
            ex.printStackTrace();
        }
        return Collections.emptyList();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy