Package javax.ws.rs.core

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


        MediaType mt1 = new MediaType("*", "*");
        MediaType mt2 = new MediaType("text", "xml");
        List<Variant> variants =
            vb.mediaTypes(mt1, mt2).encodings("zip", "identity").add().build();
        assertEquals("4 variants need to be created", 4, variants.size());
        assertTrue(verifyVariant(variants, new Variant(mt1, (Locale)null, "zip")));
        assertTrue(verifyVariant(variants, new Variant(mt1, (Locale)null, "identity")));
        assertTrue(verifyVariant(variants, new Variant(mt2, (Locale)null, "zip")));
        assertTrue(verifyVariant(variants, new Variant(mt2, (Locale)null, "identity")));
    }
View Full Code Here


        MediaType mt1 = new MediaType("*", "*");
        MediaType mt2 = new MediaType("text", "xml");
        List<Variant> variants = vb.mediaTypes(mt1, mt2).languages(new Locale("en"),
                                                                   new Locale("fr")).add().build();
        assertEquals("8 variants need to be created", 4, variants.size());
        assertTrue(verifyVariant(variants, new Variant(mt1, new Locale("en"), null)));
        assertTrue(verifyVariant(variants, new Variant(mt1, new Locale("fr"), null)));
        assertTrue(verifyVariant(variants, new Variant(mt2, new Locale("en"), null)));
        assertTrue(verifyVariant(variants, new Variant(mt2, new Locale("fr"), null)));
    }
View Full Code Here

    public void testBuildLangAndEnc() {
        VariantListBuilderImpl vb = new VariantListBuilderImpl();
        List<Variant> variants = vb.languages(new Locale("en"),
                                              new Locale("fr")).encodings("zip", "identity").add().build();
        assertEquals("4 variants need to be created", 4, variants.size());
        assertTrue(verifyVariant(variants, new Variant(null, new Locale("en"), "zip")));
        assertTrue(verifyVariant(variants, new Variant(null, new Locale("en"), "identity")));
        assertTrue(verifyVariant(variants, new Variant(null, new Locale("fr"), "zip")));
        assertTrue(verifyVariant(variants, new Variant(null, new Locale("fr"), "identity")));
    }
View Full Code Here

    public void testBuildLang() {
        VariantListBuilderImpl vb = new VariantListBuilderImpl();
        List<Variant> variants =
            vb.languages(new Locale("en"), new Locale("fr")).add().build();
        assertEquals("2 variants need to be created", 2, variants.size());
        assertTrue(verifyVariant(variants, new Variant(null, new Locale("en"), null)));
        assertTrue(verifyVariant(variants, new Variant(null, new Locale("en"), null)));
    }
View Full Code Here

    public void testBuildEnc() {
        VariantListBuilderImpl vb = new VariantListBuilderImpl();
        List<Variant> variants =
            vb.encodings("zip", "identity").add().build();
        assertEquals("2 variants need to be created", 2, variants.size());
        assertTrue(verifyVariant(variants, new Variant(null, (Locale)null, "zip")));
        assertTrue(verifyVariant(variants, new Variant(null, (Locale)null, "identity")));
    }
View Full Code Here

    public void testBuildType() {
        VariantListBuilderImpl vb = new VariantListBuilderImpl();
        List<Variant> variants =
            vb.mediaTypes(new MediaType("*", "*"), new MediaType("text", "xml")).add().build();
        assertEquals("2 variants need to be created", 2, variants.size());
        assertTrue(verifyVariant(variants, new Variant(new MediaType("*", "*"), (Locale)null, null)));
        assertTrue(verifyVariant(variants, new Variant(new MediaType("text", "xml"), (Locale)null, null)));
    }
View Full Code Here

        return createCorrectVariant(responseObj, headers, null);
    }

    protected static Response createCorrectVariant(Object responseObj, HttpHeaders headers, javax.ws.rs.core.Response.Status status) {
        Response.ResponseBuilder responseBuilder = null;
        Variant v = getVariant(headers);
        if( v == null ) {
            v = defaultVariant;
        }
        if( status != null ) {
            responseBuilder = Response.status(status).entity(responseObj).variant(v);
View Full Code Here

        return createCorrectVariant(responseObj, headers, null);
    }
   
    protected static Response createCorrectVariant(Object responseObj, HttpHeaders headers, javax.ws.rs.core.Response.Status status) {
        ResponseBuilder responseBuilder = null;
        Variant v = getVariant(headers);
        if( v == null ) {
            v = defaultVariant;
        }
        if( status != null ) {
            responseBuilder = Response.status(status).entity(responseObj).variant(v);
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

        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"));
        list.add(new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("es"), "utf-8"));
        list.add(new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "abc"));
        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.