[JBoss Seam] - Help w/ a custom RESTful Servlet with EJBs
by rmcdonough
I am working on a REST toolkit which routes URI to an invoker and marshalls entity beans to XML using JAXB. So far, everything is working pretty good. One issue I have is that the marshalling/unmarshalling is done on the web tier. The marshaller is writing directly to the Servlet OutputStream and reading directly from the Servelt InputStream. To get a better idea of what I am up to, please have a look here:
http://www.damnhandy.com/2007/02/21/resteasy-preview-a-restful-web-servic...
When using a SessionBean, I run into the obvious problem of getting a LazyInitializationException from Hibernate. To get around it, I'm starting a UserTransaction in the servlet if the WebResource is an EJB. This isn't ideal because I may not always want to start a transaction in there.
Seam appears to offer a much more elegant solution to this type of issue, so I have started creating a custom servlet that could hook into Seam. The SeamRemotingServlet isn't quite adaptable to what I'm trying to do, but I have started taking it apart to understand what it does. What my servlet needs to do is the following:
* Get the path info and look up the ResourceInvoker (effectively a RequestHandler)
* Calls the invoke() method on the ResourceInvoker and execute the Java method. The return value is generally an entity bean that will be marshalled to XML but it may not have been fully initialized yet.
* If the method has a return value, it is marshalled to XML.
My experimentation so far has yielded this in my service() method:
|
| ResourceInvoker invoker =
| ResourceDispatcher.instance().findResourceInvoker(request.getPathInfo());
| if(invoker != null) {
| logger.info("Executing Method: "+request.getMethod());
| try {
| HttpSession session = request.getSession(true);
| Lifecycle.setPhaseId(PhaseId.INVOKE_APPLICATION);
| Lifecycle.setServletRequest(request);
| Lifecycle.beginRequest(getServletContext(), session, request);
| invoker.invoke(request, response);
| } finally {
| Lifecycle.endRequest();
| Lifecycle.setServletRequest(null);
| Lifecycle.setPhaseId(null);
| }
| } else { ...
|
At the moment, I still get a LazyInitializationException and I am not sure why? I also don't know that I need to be utilizing the HttpSession, but I'm sure on weather or not it's required for something like this. Any pointers woudl be greatly appreciated!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4020952#4020952
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4020952
19Â years, 2Â months
[JBoss jBPM] - Re: When will 3.2 be released ?
by kukeltje
Date: I can't that is up to Tom, Koen, Alex, David etc...
Latest news from August 2006: I did not look, but it could be. Why does that worry you? Look at how active the forum is, how nice things develop in CVS, what get's added to the wiki, releases 3.1.x ones and 3.2 alpha, beta etc....
A way to help: Sure, look at some open issues, see if there are ones you think you can help out one. Comment on that issue (to check someone is not already working on it, happens now and then), create a patch, submit it and when you've done that a few times, you can get committer access.
Ronald
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4020944#4020944
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4020944
19Â years, 2Â months