0

in our previous project we have used Viewable (at that time we had Jersey as an implementation of JAX-RS). Now we want to run it in WebSphere 8.5. It is a JEE6 server and Viewable is not supported by default of JAX-RS. As implementation of JAX-RS Apache Wink is used there.

What is the best way for answers as HTML with internal objects? We want to use a rendering engine.

Thanx, Robert

Robert
  • 126
  • 11

1 Answers1

1

If you need to display simple jsp page you can just inject request and do the normal forward like this:

@Path("/service")
public class RestService {

    @Context
    HttpServletRequest request;
    @Context
    HttpServletResponse response;


    @GET
    @Path("/getPage")
    public void getPage() {
        try {
            request.getRequestDispatcher("/mypage.jsp").forward(request, response);
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
} 
Gas
  • 17,601
  • 4
  • 46
  • 93
  • Thax, but we need to out some information to the JSP. Viewable with POJO-Model was very good. Is there other possibility? – Robert Dec 22 '14 at 16:49
  • @Robert This example is simplification, you can use `request.setAttribute()` to pass to jsp any information you need. You could also invoke servlet instead of jsp if you need some other processing (you didn't write what rendering engine you use, and what info you need to pass). The other way would be to replace wink with Jersey, see [this post](http://stackoverflow.com/questions/24684958/jax-rs-jersey-2-10-support-in-websphere-8/24713878#24713878), but you will loose some functionality e.g. CDI integration. – Gas Dec 22 '14 at 19:36
  • It works very good. One more question: what is the best way for use Dependency Injection in JEE6 / JAX-RS without Jersey? We would use CDI.but we also need it for a embeded server (Jetty or Grizzly). It is for tests. – Robert Jan 16 '15 at 20:40
  • @Robert I'm sorry, but I don't fully understand. What you mean by 'use it without Jersey?' And why do you need embedded server? Cant you juat test on the external server? It shouldn't be a problem for jax-rs service testing. In general you shouldn't test on the different environment/implementation, as you may have different results. – Gas Jan 17 '15 at 08:38
  • Thans for your answer. I mean: in JEE5 with Websphere 7 we used Jersey as implementation of JAX-RS. There is DI with [provider possible]( https://jersey.java.net/documentation/latest/ioc.html ). We also had a [Jersey Test] ( https://jersey.java.net/documentation/latest/test-framework.html) with Grizzly as In-Memory container for the tests. Here we injected mocks to test resources. It were test for the HTTP-API of the app. We were very satisfied with this. – Robert Jan 17 '15 at 13:11
  • Now we have Websphere 8.5 with JEE6 and we want use JAX-RS from Websphere (our admins want this :-( ). IBM uses Apache-Wink as implementation for JAX-RS. Bot we look for alternatives for DI in this container. We want to have this test with embeded container. I hope my explanation is clear for this problem. – Robert Jan 17 '15 at 13:12
  • @Robert WebSphere 8.5 supports [Java CDI 1.0](http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/cweb_cdi.html) with JAX-RS without any strange configuration, you just need `beans.xml` in the `WEB-INF` folder. I'm not familiar with Grizzly but you can check [this](https://djna.wordpress.com/2009/12/04/wink-clients-and-unit-testing-jax-rs-services/) for testing Wink Jax-rs services – Gas Jan 17 '15 at 14:14