Package org.jboss.resteasy.core

Examples of org.jboss.resteasy.core.Dispatcher


   public void init(ServletContext servletContext, ConfigurationBootstrap bootstrap, HttpRequestFactory requestFactory, HttpResponseFactory responseFactory) throws ServletException
   {
      this.requestFactory = requestFactory;
      this.responseFactory = responseFactory;
      ResteasyProviderFactory globalFactory = (ResteasyProviderFactory) servletContext.getAttribute(ResteasyProviderFactory.class.getName());
      Dispatcher globalDispatcher = (Dispatcher) servletContext.getAttribute(Dispatcher.class.getName());

      String application = bootstrap.getInitParameter("javax.ws.rs.Application");
      String useGlobalStr = bootstrap.getInitParameter("resteasy.servlet.context.deployment");
      boolean useGlobal = globalFactory != null;
      if (useGlobalStr != null) useGlobal = Boolean.parseBoolean(useGlobalStr);
View Full Code Here


   }

   @Test
   public void test() throws Exception
   {
      final Dispatcher dispatcher = EmbeddedContainer.start().getDispatcher();
      try
      {
         dispatcher.getRegistry().addPerRequestResource(FormResourceImpl.class);
         final FormResource client = ProxyFactory.create(FormResource.class, generateBaseUrl());
         final String result = client.put("value");
         Assert.assertEquals(result, "value");
         final String result1 = createClientRequest("/form").formParameter("value", "value").post(
                 String.class).getEntity();
View Full Code Here

   }

   @Test
   public void testSubresource() throws Exception
   {
      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();

      dispatcher.getRegistry().addPerRequestResource(BaseResource.class);
      {
         MockHttpRequest request = MockHttpRequest.get("/base/1/resources");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals(Subresource.class.getName(), response.getContentAsString());
      }

      /*
      HttpClient client = new HttpClient();
      GetMethod method = createGetMethod("/base/1/resources");
      try
      {
         int status = client.executeMethod(method);
         Assert.assertEquals(status, HttpResponseCodes.SC_OK);
         String response = method.getResponseBodyAsString();
         Assert.assertEquals(Subresource.class.getName(), response);
      }
      catch (IOException e)
      {
         throw new RuntimeException(e);
      }
      method.releaseConnection();
      */

      {
         MockHttpRequest request = MockHttpRequest.get("/base/1/resources/subresource2/stuff/2/bar");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals(Subresource2.class.getName() + "-2", response.getContentAsString());
      }
View Full Code Here

   }

   @Test
   public void testSameUri() throws Exception
   {
      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();

      dispatcher.getRegistry().addPerRequestResource(Directory.class);
      {
         MockHttpRequest request = MockHttpRequest.delete("/directory/receivers/1");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);


         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals(Directory.class.getName(), new String(response.getOutput()));
      }
View Full Code Here

   }

   @Test
   public void testAnnotationFreeSubresource() throws Exception
   {
      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();

      dispatcher.getRegistry().addPerRequestResource(CollectionResource.class);
      {
         MockHttpRequest request = MockHttpRequest.get("/collection/annotation_free_subresource");
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("got", response.getContentAsString());
         Assert.assertNotNull(response.getOutputHeaders().get("Content-Type"));
         Assert.assertTrue(response.getOutputHeaders().get("Content-Type").size() > 0);
         Assert.assertEquals(MediaType.TEXT_PLAIN_TYPE, response.getOutputHeaders().get("Content-Type").get(0));
      }

      {
         MockHttpRequest request = MockHttpRequest.post("/collection/annotation_free_subresource");
         request.content("hello!".getBytes()).contentType(MediaType.TEXT_PLAIN);
         MockHttpResponse response = new MockHttpResponse();

         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
         Assert.assertEquals("posted: hello!", response.getContentAsString());
      }
   }
View Full Code Here

   }

   @Test
   public void testDoubleId() throws Exception
   {
      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
      dispatcher.getRegistry().addPerRequestResource(Locator.class);
      {
         MockHttpRequest request = MockHttpRequest.get("/1/2");
         MockHttpResponse response = new MockHttpResponse();
         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
      }

   }
View Full Code Here

   }

   @Test
   public void testDoubleIdAsPathSegment() throws Exception
   {
      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
      dispatcher.getRegistry().addPerRequestResource(Locator2.class);
      {
         MockHttpRequest request = MockHttpRequest.get("/1/2");
         MockHttpResponse response = new MockHttpResponse();
         dispatcher.invoke(request, response);

         Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
      }

   }
View Full Code Here

   @Test
   public void testMultiple() throws Exception
   {
      String path = "/;name=bill;ssn=111/children/;name=skippy;ssn=3344";
      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
      dispatcher.getRegistry().addPerRequestResource(Resource.class);
      MockHttpRequest request = MockHttpRequest.get(path);
      MockHttpResponse response = new MockHttpResponse();
      dispatcher.invoke(request, response);
      Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
   }
View Full Code Here

   @Test
   public void testMultiple2() throws Exception
   {
      String path = "/stuff/;name=first;ssn=111/;name=second;ssn=3344/first";
      Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
      dispatcher.getRegistry().addPerRequestResource(Resource.class);
      MockHttpRequest request = MockHttpRequest.get(path);
      MockHttpResponse response = new MockHttpResponse();
      dispatcher.invoke(request, response);
      Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
   }
View Full Code Here

    @BeforeMethod
    public final void prepareRestEasyFramework() {
        MockitoAnnotations.initMocks(this);
        when(jndiBackedConfig.getEnabledAuthenticationPolicies()).thenReturn(
                newHashSet(AuthenticationType.INTERNAL.name()));
        Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
        prepareSeamAutowire();
        prepareAccount();
        prepareResources();
        prepareExceptionMappers();
        prepareProviders();

        // register resources
        for (Object obj : resources) {
            ResourceFactory factory = new MockResourceFactory(obj);
            dispatcher.getRegistry().addResourceFactory(factory);
        }

        // register Exception Mappers
        for (Class<? extends ExceptionMapper<? extends Throwable>> mapper : exceptionMappers) {
            dispatcher.getProviderFactory().addExceptionMapper(mapper);
        }

        // register Providers
        for (Class<?> provider : providers) {
            dispatcher.getProviderFactory().registerProvider(provider);
        }

        // register Provider instances
        for (Object providerInstance : providerInstances) {
            dispatcher.getProviderFactory().registerProviderInstance(
                    providerInstance);
        }

        InMemoryClientExecutor executor =
                new InMemoryClientExecutor(dispatcher);
View Full Code Here

TOP

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

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.