Package javax.ws.rs.core

Examples of javax.ws.rs.core.Variant$VariantListBuilder


        public Response getOnlyMediaType(@Context Request request) {
            List<Variant> responseVariants =
                Variant.mediaTypes(MediaType.TEXT_PLAIN_TYPE,
                                   MediaType.APPLICATION_XML_TYPE,
                                   MediaType.APPLICATION_JSON_TYPE).add().build();
            Variant bestResponseVariant = request.selectVariant(responseVariants);
            if (bestResponseVariant != null) {
                return Response.ok("Hello world!").variant(request.selectVariant(responseVariants))
                    .build();
            }
            return Response.notAcceptable(responseVariants).build();
View Full Code Here


        @GET
        @Path("language")
        public Response getOnlyLanguage(@Context Request request) {
            List<Variant> responseVariants =
                Variant.languages(Locale.ENGLISH, Locale.FRENCH, Locale.KOREAN).add().build();
            Variant bestResponseVariant = request.selectVariant(responseVariants);
            if (bestResponseVariant != null) {
                return Response.ok("Hello world!").variant(bestResponseVariant).build();
            }
            return Response.notAcceptable(responseVariants).build();
        }
View Full Code Here

        @Path("encoding")
        public Response getOnlyEncoding(@Context Request request) {
            List<Variant> responseVariants =
                Collections.unmodifiableList(Variant.encodings("gzip", "identity", "deflate").add()
                    .build());
            Variant bestResponseVariant = request.selectVariant(responseVariants);
            if (bestResponseVariant != null) {
                return Response.ok("Hello world!").variant(bestResponseVariant).build();
            }
            return Response.notAcceptable(responseVariants).build();
        }
View Full Code Here

        @GET
        @Path("noidentityencoding")
        public Response getNoIdentityEncoding(@Context Request request) {
            List<Variant> responseVariants =
                Collections.unmodifiableList(Variant.encodings("gzip", "deflate").add().build());
            Variant bestResponseVariant = request.selectVariant(responseVariants);
            if (bestResponseVariant != null) {
                return Response.ok("Hello world!").variant(bestResponseVariant).build();
            }
            return Response.notAcceptable(responseVariants).build();
        }
View Full Code Here

            List<Variant> responseVariants =
                Variant.mediaTypes(MediaType.valueOf(MediaType.TEXT_PLAIN + ";charset=iso-8859-1"),
                                   MediaType.valueOf(MediaType.TEXT_PLAIN + ";charset=UTF-8"),
                                   MediaType.valueOf(MediaType.TEXT_PLAIN + ";charset=shift_jis"))
                    .add().build();
            Variant bestResponseVariant = request.selectVariant(responseVariants);
            if (bestResponseVariant != null) {
                return Response.ok("Hello world!").variant(bestResponseVariant).build();
            }
            return Response.notAcceptable(responseVariants).build();
        }
View Full Code Here

                                                                MediaType.APPLICATION_JSON_TYPE,
                                                                MediaType.TEXT_PLAIN_TYPE)
                    .encodings("gzip", "identity", "deflate").languages(Locale.ENGLISH,
                                                                        Locale.FRENCH,
                                                                        Locale.US).add().build());
            Variant bestResponseVariant = request.selectVariant(responseVariants);
            if (bestResponseVariant != null) {
                return Response.ok("Hello world!").variant(bestResponseVariant).build();
            }
            return Response.notAcceptable(responseVariants).build();
        }
View Full Code Here

                                    .valueOf(MediaType.APPLICATION_JSON + ";charset=iso-8859-1"),
                                MediaType.valueOf(MediaType.TEXT_PLAIN + ";charset=iso-8859-1"))
                    .encodings("gzip", "identity", "deflate").languages(Locale.ENGLISH,
                                                                        Locale.FRENCH,
                                                                        Locale.US).add().build());
            Variant bestResponseVariant = request.selectVariant(responseVariants);
            if (bestResponseVariant != null) {
                return Response.ok("Hello world!").variant(bestResponseVariant).build();
            }
            return Response.notAcceptable(responseVariants).build();
        }
View Full Code Here

       
        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
        m.putSingle("Content-Type", "text/xml");
        m.putSingle("Content-Language", "en");
        m.putSingle("Content-Encoding", "gzip");
        Variant v = new Variant(MediaType.TEXT_XML_TYPE, new Locale("en"), "gzip");
       
        checkBuild(Response.ok().variant(v).build(),
                   200, null, m);
    }
View Full Code Here

        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
        m.add("Accept", "application/json");
        m.add("Accept", "application/xml");
        m.add("Vary", "Accept");

        Variant json = new Variant(MediaType.APPLICATION_JSON_TYPE, (String)null, null);
        Variant xml = new Variant(MediaType.APPLICATION_XML_TYPE, (String)null, null);

        checkBuild(Response.ok().variants(json, xml).build(), 200, null, m);
    }
View Full Code Here

        metadata.putSingle(HttpHeaders.ACCEPT, "application/xml");
        metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en");
        metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "utf-8");
       
        List<Variant> list = new ArrayList<Variant>();
        list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "utf-8"));
        assertNull(new RequestImpl(m).selectVariant(list));
       
    }
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.Variant$VariantListBuilder

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.