Hi

Is there an easy way to test (inline) a JAX-RS service method that uses
RequestDispatcherProvider.

I have been using a JAXRSServerFactoryBean  for all my (integration)
unit tests for my typical JAX-RS methods.

 

However, when using a RequestDispatcherProvider, it calls
getRequestDispatcher on the context handler in order to delegate to the
resource (eg a JSP ), but the Jetty implementation of
ContextHandler.getRequestDispatcher  simply returns null - so the JSP
resource is never delegated to, and the service method returns a 500
status.

 

EG in the following  simple example,  when the RequestDispatcherProvider
is invoked, it calls the getRequestDispatcher("/test.jsp")  but the
Jetty implemtmnation of that method is hardcoded to return null

 

Any help appreciated:

Thanks

Paul

 

    @Before

    public void setup(){

        server = new MyRestServer();

        List<Object> providers = new ArrayList<Object>();

        RequestDispatcherProvider requestDispatcherProvider = new
RequestDispatcherProvider();

        requestDispatcherProvider.setResourcePath("/test.jsp");

        requestDispatcherProvider.setScope("request");

        providers.add(requestDispatcherProvider);

 

        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

        sf.setResourceClasses(MyRestServer.class);

        sf.setResourceProvider(MyRestServer.class, new
SingletonResourceProvider(server));

        sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);

        sf.setProviders(providers);

        sf.setAddress(REST_SERVER_URL);

        sf.create();

        sf.getDestinationFactory();

 

        httpClient = new HttpClient();

        getMethod = new GetMethod();

 

    }

 

 

    @Test

    public void getStatusMetadataServiceOk() throws Exception {

        String path = REST_SERVER_URL + "/servicestatus";

        URI uri = new URI(path, false);

        getMethod.setURI(uri);

 

        httpClient.executeMethod(getMethod);

 

        // verifiy the answer was actually hit..

        int status = getMethod.getStatusCode();

        String response = getMethod.getResponseBodyAsString();

        System.out.println(response);

        assertEquals(200, status);

    }

 

 


This e-mail (and any attachments) is confidential and may contain personal 
views which are not the views of the BBC unless specifically stated. If you 
have received it in error, please delete it from your system. Do not use, copy 
or disclose the information in any way nor act in reliance on it and notify the 
sender immediately.
 
Please note that the BBC monitors e-mails sent or received. Further 
communication will signify your consent to this

This e-mail has been sent by one of the following wholly-owned subsidiaries of 
the BBC:
 
BBC Worldwide Limited, Registration Number: 1420028 England, Registered 
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World News Limited, Registration Number: 04514407 England, Registered 
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World Distribution Limited, Registration Number: 04514408, Registered 
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ

 
 

Reply via email to