Package org.jboss.resteasy.core.request

Examples of org.jboss.resteasy.core.request.ServerDrivenNegotiation


{

   @Test
   public void mostSpecific()
   {
      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      negotiation.setAcceptHeaders(Arrays.asList("text/plain"));
      negotiation.setAcceptCharsetHeaders(Arrays.asList("UTF-8"));
      negotiation.setAcceptEncodingHeaders(Arrays.asList("gzip"));
      negotiation.setAcceptLanguageHeaders(Arrays.asList("en-gb"));

      MediaType mediaTypeWithCharset = MediaType.valueOf("text/plain; charset=UTF-8");
      MediaType mediaType = MediaType.valueOf("text/plain");
      String encoding = "gzip";
      Locale locale = Locale.UK;

      List<Variant> available = new ArrayList<Variant>();
      available.add(new Variant(mediaTypeWithCharset, null, null));
      available.add(new Variant(mediaTypeWithCharset, locale, null));
      available.add(new Variant(mediaTypeWithCharset, null, encoding));
      available.add(new Variant(mediaTypeWithCharset, locale, encoding));
      available.add(new Variant(mediaType, null, null));
      available.add(new Variant(mediaType, locale, null));
      available.add(new Variant(mediaType, null, encoding));
      available.add(new Variant(mediaType, locale, encoding));
      available.add(new Variant(null, locale, null));
      available.add(new Variant(null, locale, encoding));
      available.add(new Variant(null, null, encoding));

      // Assert all acceptable:
      for (Variant variant : available)
         assertEquals(variant, negotiation.getBestMatch(Arrays.asList(variant)));

      Variant best = negotiation.getBestMatch(available);
      assertNotNull(best);
      assertEquals(mediaTypeWithCharset, best.getMediaType());
      assertEquals(encoding, best.getEncoding());
      assertEquals(locale, best.getLanguage());
   }
View Full Code Here


   @Test
   public void mostSpecificMediaType()
   {
      String header = "text/*, text/html, text/html;level=1, */*";
      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      negotiation.setAcceptHeaders(Arrays.asList(header));

      Variant o1 = new Variant(MediaType.valueOf("text/html;level=1"), null, null);
      Variant o2 = new Variant(MediaType.valueOf("text/html"), null, null);
      Variant o3 = new Variant(MediaType.valueOf("text/*"), null, null);
      Variant o4 = new Variant(MediaType.valueOf("*/*"), null, null);

      List<Variant> available = new ArrayList<Variant>();
      available.add(o4);
      assertEquals(o4, negotiation.getBestMatch(available));
      available.add(o3);
      assertEquals(o3, negotiation.getBestMatch(available));
      available.add(o2);
      assertEquals(o2, negotiation.getBestMatch(available));
      available.add(o1);
      assertEquals(o1, negotiation.getBestMatch(available));
   }
View Full Code Here

   @Test
   public void mediaTypeQualityFactor()
   {
      String header1 = "text/*;q=0.3, text/html;q=0.7, text/html;level=1";
      String header2 = "text/html;level=2;q=0.4, */*;q=0.5";
      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      negotiation.setAcceptHeaders(Arrays.asList(header1, header2));
      negotiation.setAcceptLanguageHeaders(Arrays.asList("en"));

      Variant q03 = new Variant(MediaType.valueOf("text/plain"), null, null);
      Variant q04 = new Variant(MediaType.valueOf("text/html;level=2"), null, null);
      Variant q05 = new Variant(MediaType.valueOf("image/jpeg"), null, null);
      Variant q07 = new Variant(MediaType.valueOf("text/html"), null, null);
      Variant q07plus = new Variant(MediaType.valueOf("text/html;level=3"), null, null);
      Variant q10 = new Variant(MediaType.valueOf("text/html;level=1"), null, null);

      List<Variant> available = new ArrayList<Variant>();
      available.add(q03);
      assertEquals(q03, negotiation.getBestMatch(available));
      available.add(q04);
      assertEquals(q04, negotiation.getBestMatch(available));
      available.add(q05);
      assertEquals(q05, negotiation.getBestMatch(available));
      available.add(q07);
      assertEquals(q07, negotiation.getBestMatch(available));
      available.add(q07plus);
      assertEquals(q07plus, negotiation.getBestMatch(available));
      available.add(q10);
      assertEquals(q10, negotiation.getBestMatch(available));
   }
View Full Code Here

   public Variant selectVariant(List<Variant> variants) throws IllegalArgumentException
   {
      if (variants == null || variants.size() == 0) throw new IllegalArgumentException("Variant list must not be zero");

      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      MultivaluedMap<String,String> requestHeaders = headers.getRequestHeaders();
      negotiation.setAcceptHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT));
      negotiation.setAcceptCharsetHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_CHARSET));
      negotiation.setAcceptEncodingHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_ENCODING));
      negotiation.setAcceptLanguageHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_LANGUAGE));

      varyHeader = ResponseBuilderImpl.createVaryHeader(variants);
      return negotiation.getBestMatch(variants);
   }
View Full Code Here

   public Variant selectVariant(List<Variant> variants) throws IllegalArgumentException
   {
      if (variants == null || variants.size() == 0) throw new IllegalArgumentException("Variant list must not be zero");

      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      MultivaluedMap<String, String> requestHeaders = headers.getRequestHeaders();
      negotiation.setAcceptHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT));
      negotiation.setAcceptCharsetHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_CHARSET));
      negotiation.setAcceptEncodingHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_ENCODING));
      negotiation.setAcceptLanguageHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_LANGUAGE));

      varyHeader = ResponseBuilderImpl.createVaryHeader(variants);
      return negotiation.getBestMatch(variants);
   }
View Full Code Here

   public Variant selectVariant(List<Variant> variants) throws IllegalArgumentException
   {
      if (variants == null || variants.size() == 0) throw new IllegalArgumentException("Variant list must not be zero");

      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      MultivaluedMap<String, String> requestHeaders = headers.getRequestHeaders();
      negotiation.setAcceptHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT));
      negotiation.setAcceptCharsetHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_CHARSET));
      negotiation.setAcceptEncodingHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_ENCODING));
      negotiation.setAcceptLanguageHeaders(requestHeaders.get(HttpHeaderNames.ACCEPT_LANGUAGE));

      varyHeader = ResponseBuilderImpl.createVaryHeader(variants);
      response.getOutputHeaders().add(HttpHeaderNames.VARY, varyHeader);
      return negotiation.getBestMatch(variants);
   }
View Full Code Here

{

   @Test
   public void mostSpecific()
   {
      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      negotiation.setAcceptHeaders(Arrays.asList("text/plain"));
      negotiation.setAcceptCharsetHeaders(Arrays.asList("UTF-8"));
      negotiation.setAcceptEncodingHeaders(Arrays.asList("gzip"));
      negotiation.setAcceptLanguageHeaders(Arrays.asList("en-gb"));

      MediaType mediaTypeWithCharset = MediaType.valueOf("text/plain; charset=UTF-8");
      MediaType mediaType = MediaType.valueOf("text/plain");
      String encoding = "gzip";
      Locale locale = Locale.UK;

      List<Variant> available = new ArrayList<Variant>();
      available.add(new Variant(mediaTypeWithCharset, (String)null, (String)null));
      available.add(new Variant(mediaTypeWithCharset, locale, null));
      available.add(new Variant(mediaTypeWithCharset, (String)null, encoding));
      available.add(new Variant(mediaTypeWithCharset, locale, encoding));
      available.add(new Variant(mediaType, (String)null, (String)null));
      available.add(new Variant(mediaType, locale, null));
      available.add(new Variant(mediaType, (String)null, encoding));
      available.add(new Variant(mediaType, locale, encoding));
      available.add(new Variant(null, locale, null));
      available.add(new Variant(null, locale, encoding));
      available.add(new Variant((MediaType)null,(String)null, encoding));

      // Assert all acceptable:
      for (Variant variant : available)
         assertEquals(variant, negotiation.getBestMatch(Arrays.asList(variant)));

      Variant best = negotiation.getBestMatch(available);
      assertNotNull(best);
      assertEquals(mediaTypeWithCharset, best.getMediaType());
      assertEquals(encoding, best.getEncoding());
      assertEquals(locale, best.getLanguage());
   }
View Full Code Here

   @Test
   public void mostSpecificMediaType()
   {
      String header = "text/*, text/html, text/html;level=1, */*";
      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      negotiation.setAcceptHeaders(Arrays.asList(header));

      Variant o1 = new Variant(MediaType.valueOf("text/html;level=1"), (String)null, (String)null);
      Variant o2 = new Variant(MediaType.valueOf("text/html"), (String)null, null);
      Variant o3 = new Variant(MediaType.valueOf("text/*"), (String)null, null);
      Variant o4 = new Variant(MediaType.valueOf("*/*"), (String)null, null);

      List<Variant> available = new ArrayList<Variant>();
      available.add(o4);
      assertEquals(o4, negotiation.getBestMatch(available));
      available.add(o3);
      assertEquals(o3, negotiation.getBestMatch(available));
      available.add(o2);
      assertEquals(o2, negotiation.getBestMatch(available));
      available.add(o1);
      assertEquals(o1, negotiation.getBestMatch(available));
   }
View Full Code Here

   @Test
   public void mediaTypeQualityFactor()
   {
      String header1 = "text/*;q=0.3, text/html;q=0.7, text/html;level=1";
      String header2 = "text/html;level=2;q=0.4, */*;q=0.5";
      ServerDrivenNegotiation negotiation = new ServerDrivenNegotiation();
      negotiation.setAcceptHeaders(Arrays.asList(header1, header2));
      negotiation.setAcceptLanguageHeaders(Arrays.asList("en"));

      Variant q03 = new Variant(MediaType.valueOf("text/plain"), (String)null, null);
      Variant q04 = new Variant(MediaType.valueOf("text/html;level=2"), (String)null, null);
      Variant q05 = new Variant(MediaType.valueOf("image/jpeg"), (String)null, null);
      Variant q07 = new Variant(MediaType.valueOf("text/html"), (String)null, null);
      Variant q07plus = new Variant(MediaType.valueOf("text/html;level=3"), (String)null, null);
      Variant q10 = new Variant(MediaType.valueOf("text/html;level=1"), (String)null, null);

      List<Variant> available = new ArrayList<Variant>();
      available.add(q03);
      assertEquals(q03, negotiation.getBestMatch(available));
      available.add(q04);
      assertEquals(q04, negotiation.getBestMatch(available));
      available.add(q05);
      assertEquals(q05, negotiation.getBestMatch(available));
      available.add(q07);
      assertEquals(q07, negotiation.getBestMatch(available));
      available.add(q07plus);
      assertEquals(q07plus, negotiation.getBestMatch(available));
      available.add(q10);
      assertEquals(q10, negotiation.getBestMatch(available));
   }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.core.request.ServerDrivenNegotiation

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.