I have injected my simple pojo ejb into web service interface and trying to intercept the method simple pojo by using the EJB interceptor but issue is that instance of injected pojo will hold the value that is setted in earlier request of web service
How to solve this issue.
Thanks
Related
I have spring session scoped bean. That bean is using application scoped beans, and there's and error when the container tries to serialize the session.
I remember that problem from JSF applications, and in one project, we've solved that using serializable proxies. The injected bean was the proxy wrapper which fetched the singleton instance from the application context. Unfortunately, I can't remember how exactly it was called and was it a build-in solution or some external thing.
How to wrap spring beans in serializable proxies? Does Spring provide such functionality? AFAIR there was some special annotation to mark the references that should be wrapped in such proxy.
The feature is called scoped proxy and can be triggered via annotation to the service, that will be injected to session scoped beans:
#Scope(proxyMode = ScopedProxyMode.INTERFACES)
More details in question:
Spring session-scoped beans (controllers) and references to services, in terms of serialization
I'm using EJB 3 and JBoss AS 6.0.0.Final. I have a stateless session bean with the annotations #Stateless and #WebService. When I add the annotation #Singleton, the deployment is in error showing the message:
...name=ServiceBean, service=ejb3 is already installed
What can I do to avoid the deployment error?
You can use #WebService and #Stateless or #WebService and #Singleton in the same bean which makes perfectly sense if you want to expose a POJO as both a web service and EJB.
Don't see much sense in using #Stateless and #Singleton in the same bean. When you use #Singleton, you are creating an EJB with all the EJB capabilities (transaction management, security, etc) exactly as with #Stateless. The only difference is how the container manages the EJB lifecycle:
#Stateless: the EJB instance is created immediately after the first request and when the request ends, the EJB is pooled and ready for reuse if another request comes in. However, if all the pooled instances are being used in the moment another request comes in for the same bean, the container creates a new instance of the same to serve that new request.
#Singleton: the EJB instance is created after the first request (by default - see #Startup to override this behavior) comes in and that will be the only instance created by the container. If another request wants to use the same EJB, the container will never create a new instance of it - the instance previously created will be used. It is like a #Stateless EJB with a pool size of 1 :) Aspects like concurrency are important when using these, but this is probably out of the scope of this post.
After playing around with example SOAP application Calculator from NetBeans, I began making my own app, using some third-party WSDL's as service models.
I managed to successfully create a web service classes from this WSDL, unfortunately, when I try to inject this service into my servlet (called ClientServlet), I got 500 error
"javax.servlet.ServletException: Error instantiating servlet class clients.ClientServlet".
The service interface methods are defined in Interface class MyServiceInterface. Don't ask me why it is that way - this service is made by third party.
When I comment out this annotation, and subsequent field declaration, then it works (but I can't use this service).
My code snippet:
#WebServiceRef(wsdlLocation="url/to/wsdl/of/my/service.wsdl")
public MyServiceInterface service;
Of course, I tried to do this without dependency injection, by direct creation of the instance of this class:
service1 = new MyService().getMyService();
MyService.java was created during importing a service from WSDL. GetMyService() method should return instance of the class that is implementing MyServiceInterface. But instead, Java throws me
exception at javax.xml.ws.Service.getPort(Service.java:92)
I am using Apache Tomcat 7.0 and Netbeans 7.0 IDE. What I should do now?
SOLVED - I just made it from scratch using GlassFish 3.1 server.
I've got a service layer which is managed by spring. Now at one point I need some informations from the httpsession. Is there a clean way to inject the httpsession directly into my servicelayer?
My portlets are not managed by spring - this point matters in my setup.
Bad idea.
The service layer shouldn't have to know anything about HTTP.
My advice is to pull the information out of the session, bind it to a (validated) object, and make that object a parameter for one of the method calls on your service's interface.
This is NOT the place for injection.
I am using the JAX-WS "WebService" annotation on a class to expose its "WebMethod"s as a web service. The class is denoted as the servlet class handling calls to "/MyService".
As essentially a servlet, I would expect an instance of this class to be created once and to basically be a singleton. I have code in the constructor of this class to create an EntityManagerFactory for assignment to a member variable. What I'm seeing is that the constructor is being called for every client request to the web service. This is not good.
Does anyone know what's going on here? Does anyone understand what I'm trying to ask? :)
Thanks.
As essentially a servlet, I would expect an instance of this class to be created once and to basically be a singleton.
It's up to container. You cannot rely on it.
Create a real singleton -- a simple Java class -- which does all the heavy lifting, and call it from the servlet.
Your topic mentions a SLSB, which I assume is "Stateless Session Bean". In Java EE 5 you can create web services either from a Stateless Session Bean, or you can annotate a class and the runtime will publish it as a webservice when deployed in a compliant web container.
In either case, neither of these are Servlets per se, and don't follow a Servlet lifecycle.