Package javax.ws.rs.core

Examples of javax.ws.rs.core.MediaType


        RuntimeContext saved = RuntimeContextTLS.getRuntimeContext();
        ClientRuntimeContext runtimeContext = new ClientRuntimeContext(providersRegistry);
        RuntimeContextTLS.setRuntimeContext(runtimeContext);
        try {
            String contentType = getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
            MediaType contentMediaType = MediaType.valueOf(contentType);
            MessageBodyReader<T> reader =
                providersRegistry.getMessageBodyReader(type,
                                                       genericType,
                                                       null,
                                                       contentMediaType,
View Full Code Here


    private boolean                errorFlow        = false;

    public void handleResponse(MessageContext context) throws Throwable {

        MediaType responseMediaType = null;
        Object result = context.getResponseEntity();

        if (result == null) {
            return;
        }

        if (result instanceof Response) {
            Response response = (Response)result;

            Object first = response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE);

            if (first != null) {
                if (first instanceof MediaType) {
                    responseMediaType = (MediaType)first;
                } else {
                    responseMediaType = MediaType.valueOf(first.toString());
                }
            }
        }

        if (responseMediaType == null) {
            Set<MediaType> producedMime = null;
            SearchResult searchResult = context.getAttribute(SearchResult.class);
            if (searchResult != null && searchResult.isFound()) {
                MethodMetadata methodMetadata = searchResult.getMethod().getMetadata();
                producedMime = methodMetadata.getProduces();
            }
            if (producedMime == null || producedMime.isEmpty()) {
                producedMime =
                    context.getAttribute(ProvidersRegistry.class)
                        .getMessageBodyWriterMediaTypes(result.getClass());
            }
            if (producedMime.isEmpty()) {
                producedMime.add(MediaType.WILDCARD_TYPE);
            }

            List<MediaType> acceptableMediaTypes =
                context.getHttpHeaders().getAcceptableMediaTypes();

            // collect all candidates
            List<CandidateMediaType> candidates = new LinkedList<CandidateMediaType>();
            for (MediaType acceptableMediaType : acceptableMediaTypes) {
                for (MediaType mediaType : producedMime) {
                    if (mediaType.isCompatible(acceptableMediaType)) {
                        MediaType candidateMediaType = null;
                        if (MediaTypeUtils.compareTo(mediaType, acceptableMediaType) > 0) {
                            candidateMediaType = mediaType;
                        } else {
                            candidateMediaType = acceptableMediaType;
                        }
View Full Code Here

        sbMain.append("</application>");
       
        m.getExchange().put(JAXRSUtils.IGNORE_MESSAGE_WRITERS, ignoreMessageWriters);
       
        HttpHeaders headers = new HttpHeadersImpl(m);
        MediaType type = headers.getAcceptableMediaTypes().contains(MediaType.APPLICATION_XML_TYPE)
                      ? MediaType.APPLICATION_XML_TYPE : WADL_TYPE; 
        return Response.ok().type(type).entity(sbMain.toString()).build();
    }
View Full Code Here

                                      Class<?> type) {
        if (type != null) {
            handleRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, type, true);
        } else {
            List<MediaType> types = ori.getConsumeTypes();
            MediaType formType = isWildcard(types) ? MediaType.APPLICATION_FORM_URLENCODED_TYPE
                : types.get(0);
            sb.append("<representation");
            sb.append(" mediaType=\"").append(formType).append("\">");
            for (Parameter pm : ori.getParameters()) {
                writeParam(sb, pm, ori);
View Full Code Here

        if (runtimeContext == null) {
            return null;
        }
        Providers providers = runtimeContext.getProviders();
        if (providers != null) {
            MediaType mediaType = runtimeContext.getHttpHeaders().getMediaType();
            if (mediaType == null) {
                mediaType = MediaType.WILDCARD_TYPE;
            }
            ContextResolver<T> contextResolver =
                providers.getContextResolver(contextClass, mediaType);
View Full Code Here

                .equals(MediaType.MEDIA_TYPE_WILDCARD)) {
                return getProvidersByWildcardMediaType(mediaType, cls);
            }
            List<ObjectFactory<T>> list = new ArrayList<ObjectFactory<T>>();
            if (!mediaType.getParameters().isEmpty()) {
                mediaType = new MediaType(type, subtype);
            }
            Set<ObjectFactory<T>> set = data.get(mediaType);
            limitByType(list, set, cls);
            set = data.get(new MediaType(type, MediaType.MEDIA_TYPE_WILDCARD));
            limitByType(list, set, cls);
            set = data.get(MediaType.WILDCARD_TYPE);
            limitByType(list, set, cls);

            return list;
View Full Code Here

            Collections.sort(compatibleList, Collections
                .reverseOrder(new Comparator<Entry<MediaType, Set<ObjectFactory<T>>>>() {

                    public int compare(Entry<MediaType, Set<ObjectFactory<T>>> o1,
                                       Entry<MediaType, Set<ObjectFactory<T>>> o2) {
                        MediaType m1 = o1.getKey();
                        MediaType m2 = o2.getKey();
                        int compareTypes = compareTypes(m1.getType(), m2.getType());
                        if (compareTypes == 0) {
                            return compareTypes(m1.getSubtype(), m2.getSubtype());
                        }
                        return compareTypes;
                    }

                    private int compareTypes(String type1, String type2) {
View Full Code Here

        public Set<MediaType> getProvidersMediaTypes(Class<?> type) {
            Set<MediaType> mediaTypes = new HashSet<MediaType>();

            l1: for (Entry<MediaType, Set<ObjectFactory<T>>> entry : data.entrySet()) {
                MediaType mediaType = entry.getKey();
                Set<ObjectFactory<T>> set = entry.getValue();
                for (ObjectFactory<T> t : set) {
                    if (GenericsUtils.isGenericInterfaceAssignableFrom(type,
                                                                       t.getInstanceClass(),
                                                                       rawType)) {
View Full Code Here

            }
        }

        void put(MediaType key, ObjectFactory<T> objectFactory) {
            if (!key.getParameters().isEmpty()) {
                key = new MediaType(key.getType(), key.getSubtype());
            }
            Set<ObjectFactory<T>> set = data.get(key);
            if (set == null) {
                set = new TreeSet<ObjectFactory<T>>(Collections.reverseOrder());
                data.put(key, set);
View Full Code Here

            .equalsIgnoreParameters(mediaType, MediaType.APPLICATION_XML_TYPE) || (mediaType
            .getType().equals("application") && mediaType.getSubtype().endsWith("+xml")));
    }

    public static MediaType clone(MediaType mt) {
        return new MediaType(mt.getType(), mt.getSubtype(), mt.getParameters());
    }
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.MediaType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.