Package org.jboss.resteasy.core

Examples of org.jboss.resteasy.core.AcceptParameterHttpPreprocessor


         // register all providers
         registration();

         if (paramMapping != null)
         {
            dispatcher.addHttpPreprocessor(new AcceptParameterHttpPreprocessor(paramMapping));
         }

         if (mediaTypeMappings != null)
         {
            Map<String, MediaType> extMap = new HashMap<String, MediaType>();
View Full Code Here


   @Test
   public void simple() throws Exception
   {

      String acceptParamName = "accept";
      AcceptParameterHttpPreprocessor processor = new AcceptParameterHttpPreprocessor(acceptParamName);

      String type = MediaType.TEXT_XML;
      HttpRequest request = MockHttpRequest.get("foo?" + acceptParamName + "=" + type);

      MediaType mediaType = MediaType.valueOf(type);

      processor.preProcess(request);

      List<MediaType> list = request.getHttpHeaders().getAcceptableMediaTypes();

      Assert.assertEquals("Incorrect acceptable list size", 1, list.size());
      Assert.assertEquals("Incorrect media type extracted", mediaType, list.get(0));
View Full Code Here

   @Test
   public void aLittleMoreComplicated() throws Exception
   {

      String acceptParamName = "bar";
      AcceptParameterHttpPreprocessor processor = new AcceptParameterHttpPreprocessor(acceptParamName);

      List<MediaType> expected = Arrays.asList(MediaType.TEXT_XML_TYPE, MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_HTML_TYPE, MediaType.APPLICATION_XHTML_XML_TYPE);

      HttpRequest request = MockHttpRequest.get("foo?" + acceptParamName + "=" + expected.get(0) + "," + expected.get(1));
      request.getHttpHeaders().getAcceptableMediaTypes().add(expected.get(2));
      request.getHttpHeaders().getAcceptableMediaTypes().add(expected.get(3));

      processor.preProcess(request);

      List<MediaType> actual = request.getHttpHeaders().getAcceptableMediaTypes();

      Assert.assertEquals("Incorrect acceptable media type extracted", expected, actual);
   }
View Full Code Here

   @Test
   public void withoutParam() throws Exception
   {

      String acceptParamName = "baz";
      AcceptParameterHttpPreprocessor processor = new AcceptParameterHttpPreprocessor(acceptParamName);

      List<MediaType> expected = Arrays.asList(MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_HTML_TYPE);

      HttpRequest request = MockHttpRequest.get("foo");
      request.getHttpHeaders().getAcceptableMediaTypes().add(expected.get(0));
      request.getHttpHeaders().getAcceptableMediaTypes().add(expected.get(1));

      processor.preProcess(request);

      List<MediaType> actual = request.getHttpHeaders().getAcceptableMediaTypes();

      Assert.assertEquals("Incorrect acceptable media type extracted", expected, actual);
   }
View Full Code Here

   @Test
   public void complex() throws Exception
   {

      String acceptParamName = "bar";
      AcceptParameterHttpPreprocessor processor = new AcceptParameterHttpPreprocessor(acceptParamName);

      List<MediaType> expected = Arrays.asList(
              MediaType.valueOf("application/xhtml+xml"),
              MediaType.valueOf("text/html"),
              MediaType.valueOf("application/xml;q=0.9"),
              MediaType.valueOf("*/*;q=0.8")
      );

      String param1 = URLEncoder.encode("application/xml;q=0.9,application/xhtml+xml,*/*;q=0.8", "UTF-8");
      String param2 = URLEncoder.encode("text/html", "UTF-8");
      HttpRequest request = MockHttpRequest.get(
              "foo?" + acceptParamName + "=" + param1 + "&" +
                      acceptParamName + "=" + param2);

      processor.preProcess(request);

      List<MediaType> actual = request.getHttpHeaders().getAcceptableMediaTypes();

      Assert.assertEquals("Incorrect acceptable media type extracted", expected, actual);
   }
View Full Code Here

      // register all providers
      registration();

      if (paramMapping != null)
      {
         dispatcher.addHttpPreprocessor(new AcceptParameterHttpPreprocessor(paramMapping));
      }

      if (mediaTypeMappings != null)
      {
         Map<String, MediaType> extMap = new HashMap<String, MediaType>();
View Full Code Here

         // register all providers
         registration();

         if (paramMapping != null)
         {
            dispatcher.addHttpPreprocessor(new AcceptParameterHttpPreprocessor(paramMapping));
         }

         if (mediaTypeMappings != null)
         {
            Map<String, MediaType> extMap = new HashMap<String, MediaType>();
View Full Code Here

         // register all providers
         registration();

         if (paramMapping != null)
         {
            providerFactory.getContainerRequestFilterRegistry().registerSingleton(new AcceptParameterHttpPreprocessor(paramMapping));
         }

         AcceptHeaderByFileSuffixFilter suffixNegotiationFilter = null;
         if (mediaTypeMappings != null)
         {
View Full Code Here

   @Test
   public void simple() throws Exception
   {

      String acceptParamName = "accept";
      AcceptParameterHttpPreprocessor processor = new AcceptParameterHttpPreprocessor(acceptParamName);

      String type = MediaType.TEXT_XML;
      HttpRequest request = MockHttpRequest.get("foo?" + acceptParamName + "=" + type);

      MediaType mediaType = MediaType.valueOf(type);

      PreMatchContainerRequestContext context = new PreMatchContainerRequestContext(request);
      processor.filter(context);

      List<MediaType> list = request.getHttpHeaders().getAcceptableMediaTypes();

      Assert.assertEquals("Incorrect acceptable list size", 1, list.size());
      Assert.assertEquals("Incorrect media type extracted", mediaType, list.get(0));
View Full Code Here

   @Test
   public void aLittleMoreComplicated() throws Exception
   {

      String acceptParamName = "bar";
      AcceptParameterHttpPreprocessor processor = new AcceptParameterHttpPreprocessor(acceptParamName);

      List<MediaType> expected = Arrays.asList(MediaType.TEXT_XML_TYPE, MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_HTML_TYPE, MediaType.APPLICATION_XHTML_XML_TYPE);

      MockHttpRequest request = MockHttpRequest.get("foo?" + acceptParamName + "=" + expected.get(0) + "," + expected.get(1));
      PreMatchContainerRequestContext context = new PreMatchContainerRequestContext(request);

      request.accept(expected.get(2));
      request.accept(expected.get(3));

      processor.filter(context);

      List<MediaType> actual = request.getHttpHeaders().getAcceptableMediaTypes();

      for (MediaType expect : expected)
      {
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.core.AcceptParameterHttpPreprocessor

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.