users@glassfish.java.net

Re: Stateful web service injection not working

From: David Pérez Villanueva <dperezvi.listas_at_gmail.com>
Date: Mon, 14 Jul 2008 18:36:48 +0200

Hi again,

it isn't a bug referred to EJBs. I'm creating a Stateful Web Service
following this user guide:
https://jax-ws.dev.java.net/jax-ws-21-ea3/docs/statefulWebservice.html.

Here is the expanation:

------------------------------------
Application service implementation classes (or providers) who'd like to
use the stateful web service support must declare @Stateful annotation
on a class. It should also have a *public static* method/field that
takes StatefulWebServiceManager.

@Stateful @WebService @Addressing
class BankAccount {
    protected final int id;
    private int balance;
    
    Account(int id) { this.id = id; }
    
    @WebMethod
    public synchronized void deposit(int amount) { balance+=amount; }

    // either via a public static field
    
    public static StatefulWebServiceManager<BankAccount> manager;
    
    // ... or via a public static method (the method name could be anything)
    
    public static void setManager(StatefulWebServiceManager<BankAccount> manager) {
       ...
    }
    
}

After your service is deployed but before you receive a first request,
the resource injection occurs on the field or the method.

----------------------------------------

The problem is that resource injection is not occurring and when you try
to get the EndPointReference from a non Stateful Web Service, a
NullPointerException occurs when you try to exec
BankAccount.manager.export(XXXX);

I found this issue
https://glassfish.dev.java.net/issues/show_bug.cgi?id=2082 but it's
closed in January 2007.


Thanks,

David Pérez.



glassfish_at_javadesktop.org escribió:
> Hi David
>
> To change a ejb from Stateless to Stateful you have only to change the annotation just before the bean.
>
> I thought I had already write this code in this thread, but I cannot find it now.
>
> You need an remote interface:
>
> @Remote
> public interface IfRemoteService{
> ...
> }
>
> Then a session bean implementing that interface, be stateless or stateful, and the attribute mappedName for you to control the name of that EJB
>
> @State... (mappedName="myFavouriteEJB")
> class BankingMortgageBean implements IfRemoteService[
> ...
> }
>
> and then in your client code you only need this
>
> IfRemoteService remoteReference = (IfRemoteService)InitialContext.doLookup("myFavouriteEJB");
>
> The state nature of the bean has nothing to do with JNDI.
>
> You can browse GF JNDI using the admin console: Application Server | JNDI Browsing.
>
> Aniceto Perez
> [Message sent by forum member 'aperezymadrid' (aperezymadrid)]
>
> http://forums.java.net/jive/thread.jspa?messageID=286460
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>