How to create an @Singleton bean that implements @WebService

EDITED: after believing that this is a NetBeans 7.0 editor bug. It is still compiled and deployed.

I want to convert my web service, which is @WebService; @ Stateless implementation in @Singleton bean, but when I replace @WebService with @Singleton annotation ... I get the image below in the IDE editor

Screen Shot of NetBeans IDE

Of course, when I do something stupid, both with @WebService and @Stateless, and with deployment in a glass shawl, I get:

serious error: annotation processing failed for ...

below is a link (there is more, but now I'm limited to two links), which led me to believe that Singleton beans can be used the way I try to use them.

http://download.oracle.com/javaee/6/tutorial/doc/gipjg.html

"Singleton session beans offers similar functionality for a session without beans state, but differs from them in that there is only one single-line bean session for each application, unlike a session pool without beans state, any of which can respond to a client request. As a session without beans state, singleton session beans can implement web service endpoints. "

This link may mean that there is a bug in the compiler that has been fixed in the jboss environment. I'm not sure if this problem is related, although I would like to hear what experienced users think.;)

https://issues.jboss.org/browse/EJBTHREE-2161

Here are derived from glass 3

INFO: Closing monitoring monitoring Metro: AMX: p = / month / server-mon [Server], type = WSEndpoint, name = soco.ws.bb.bearBearWS-BearBearImplPort INFO: portable JNDI names for EJB StateBean: [Java: global / BearBearService / StateBean soco.ws.bb.StateBean, java: global / BearBearService / StateBean] INFO: Metro monitoring username successfully set: AMX: p = / month / server-mon [Server], type = WSEndpoint, name = soco .ws.bb.bearBearWS-BearBearImplPort WARNING: The org.glassfish.webservices.JAXWSContainer@249ef1e container does not support the class com.sun.xml.ws.api.server.Module INFO: Portable JNDI names for EJB BearBearImpl: [Java: global / BearBearService / BearBearImpl soco. ws.bb.BearBearWS, java: global / BearBearService / BearBearImpl] INFO: WS00019: EJB deploy endpoint ut

Here derived from glassfish 3.0.1

INFO: Metro monitoring rooname successfully configured to: amx: pp = / mon / server-mon [server], type = WSEndpoint, name = AppleImplService-AppleImplPort WARNING: The container org.glassfish.webservices.JAXWSContainer@191f81e does not support the class com.sun.xml.ws .api.server.Module INFO: portable JNDI names for EJB AppleImpl "[Java: global / AppleService / AppleImpl com.ws.srv.MyService, Java: global / AppleService / AppleImpl] INFO: WS00019: deployed AppleService EJB endpoint listening address http: // localhost: 8080 / AppleImplService / AppleImpl INFO: AppleService was successfully deployed in 438 milliseconds

+2
source share
2 answers

This is a bug in NetBeans 7.0 editor. I managed to create and deploy WS using @WebService, @Singleton, although the service name was underlined in red to indicate a compilation error. Just checked the test to make sure the bean specification works as advertised. I will give the code below and a snapshot of my ui test.

Thanks to @home, @bkali and @Preston for their contributions.

Submitted by netbeans as an error: http://netbeans.org/bugzilla/show_bug.cgi?id=200911

Note that the state of the instance is timed out and changes from 50 to 0 after a timeout period (10 minutes) when I redeploy the service as Singleton, and not without state.

Snapshot of Test UI

Web Service Verification Code:

import javax.ejb.EJB; import javax.ejb.Singleton; import javax.jws.WebService; import javax.jws.WebParam; import javax.ejb.Stateless; @WebService(serviceName = "soco.ws.bb.bearBearWS") @Singleton //@Stateless public class BearBearImpl implements BearBearWS { int state = 0; static int staticState = 0; @EJB StateBean sb = new StateBean(); @Override public String hello(@WebParam(name = "name") String txt) { return "Hello " + txt + " !"; } @Override public void setAllState(int in) { System.out.println("setting instance state from "+state+" to "+in); state = in; System.out.println("setting static state from "+staticState+" to "+in); staticState = in; System.out.println("setting singleton state from "+sb.state+" to "+in); sb.state = in; } @Override public int getInstanceState() { System.out.println("returning instance state "+state); return state; } @Override public int getStaticState() { System.out.println("returning static state "+staticState); return staticState; } @Override public int getSingletonState() { System.out.println("returning singleton state "+sb.state); return sb.state; } } 
+2
source

As @bkail points out, JSR 109 explicitly allows a combination of both @WebService and @Singleton . Chapter 3.3.1 states:

3.3.1 Web Service Components

This specification defines two ways to implement a web service that runs in the Java EE environment, but does not limit the implementation of web services to just these tools. The first is the JAX-RPC or JAX-WS container-based extension that defines a web service as a Java class running in a web container. The second uses a limited implementation in an EJB container for an EJB session or singleton EJB session (JAX-WS services only). Other service options are possible, but they are not defined by this specification.

A workaround would be to have the @Singleton attribute attribute of the annotated member in your web services class and then delegate to this singleton:

 @WebService public class MyService { @EJB private MySingleton singleton; public void doSomeService() { this.singleton.doSomeService(); } } @Singleton public class MySingleton { // some code ... } 
+2
source

All Articles