- Ejb java lang illegalstateexception
- getEJBHome
- getEJBLocalHome
- getEnvironment
- getCallerIdentity
- getCallerPrincipal
- isCallerInRole
- isCallerInRole
- getUserTransaction
- setRollbackOnly
- getRollbackOnly
- getTimerService
- lookup
- getContextData
- java.lang.IllegalStateException: No EJB receiver available for handling (. )
- IllegalStateException
Ejb java lang illegalstateexception
The EJBContext interface provides an instance with access to the container-provided runtime context of an enterprise bean instance.
This interface is extended by the SessionContext , EntityContext , and MessageDrivenContext interfaces to provide additional methods specific to the enterprise interface bean type.
Since: EJB 1.0 See Also: SessionContext , MessageDrivenContext , EntityContext
Method Summary | |
---|---|
java.security.Identity | getCallerIdentity () Deprecated. Use Principal getCallerPrincipal() instead. |
java.security.Principal | getCallerPrincipal () Obtain the java.security.Principal that identifies the caller. |
java.util.Map | getContextData () Returns the context data associated with this invocation or lifecycle callback. |
EJBHome | getEJBHome () Obtain the enterprise bean’s remote home interface. |
EJBLocalHome | getEJBLocalHome () Obtain the enterprise bean’s local home interface. |
java.util.Properties | getEnvironment () Deprecated. Use the JNDI naming context java:comp/env to access enterprise bean’s environment. |
boolean | getRollbackOnly () Test if the transaction has been marked for rollback only. |
TimerService | getTimerService () Get access to the EJB Timer Service. |
UserTransaction | getUserTransaction () Obtain the transaction demarcation interface. |
boolean | isCallerInRole (java.security.Identity role) Deprecated. Use boolean isCallerInRole(String roleName) instead. |
boolean | isCallerInRole (java.lang.String roleName) Test if the caller has a given security role. |
java.lang.Object | lookup (java.lang.String name) Lookup a resource within the java: namespace. |
void | setRollbackOnly () Mark the current transaction for rollback. |
getEJBHome
EJBHome getEJBHome() throws java.lang.IllegalStateException
Returns: The enterprise bean’s remote home interface. Throws: java.lang.IllegalStateException — if the enterprise bean does not have a remote home interface.
getEJBLocalHome
EJBLocalHome getEJBLocalHome() throws java.lang.IllegalStateException
Returns: The enterprise bean’s local home interface. Throws: java.lang.IllegalStateException — if the enterprise bean does not have a local home interface. Since: EJB 2.0
getEnvironment
java.util.Properties getEnvironment()
Obtain the enterprise bean’s environment properties.
Note: If the enterprise bean has no environment properties this method returns an empty java.util.Properties object. This method never returns null .
Returns: The environment properties for the enterprise bean.
getCallerIdentity
java.security.Identity getCallerIdentity()
Obtain the java.security.Identity of the caller. This method is deprecated in EJB 1.1. The Container is allowed to return always null from this method. The enterprise bean should use the getCallerPrincipal method instead.
Returns: The Identity object that identifies the caller.
getCallerPrincipal
java.security.Principal getCallerPrincipal() throws java.lang.IllegalStateException
Returns: The Principal object that identifies the caller. This method never returns null . Throws: IllegalStateException — The Container throws the exception if the instance is not allowed to call this method. Since: EJB 1.1
isCallerInRole
boolean isCallerInRole(java.security.Identity role)
Test if the caller has a given role.
This method is deprecated in EJB 1.1. The enterprise bean should use the isCallerInRole(String roleName) method instead.
Parameters: role — The java.security.Identity of the role to be tested. Returns: True if the caller has the specified role.
isCallerInRole
boolean isCallerInRole(java.lang.String roleName) throws java.lang.IllegalStateException
Parameters: roleName — The name of the security role. The role must be one of the security roles that is defined in the deployment descriptor. Returns: True if the caller has the specified role. Throws: IllegalStateException — The Container throws the exception if the instance is not allowed to call this method. Since: EJB 1.1
getUserTransaction
UserTransaction getUserTransaction() throws java.lang.IllegalStateException
Obtain the transaction demarcation interface. Only enterprise beans with bean-managed transactions are allowed to to use the UserTransaction interface. As entity beans must always use container-managed transactions, only session beans or message-driven beans with bean-managed transactions are allowed to invoke this method.
Returns: The UserTransaction interface that the enterprise bean instance can use for transaction demarcation. Throws: IllegalStateException — The Container throws the exception if the instance is not allowed to use the UserTransaction interface (i.e. the instance is of a bean with container-managed transactions).
setRollbackOnly
void setRollbackOnly() throws java.lang.IllegalStateException
Mark the current transaction for rollback. The transaction will become permanently marked for rollback. A transaction marked for rollback can never commit. Only enterprise beans with container-managed transactions are allowed to use this method.
Throws: IllegalStateException — The Container throws the exception if the instance is not allowed to use this method (i.e. the instance is of a bean with bean-managed transactions).
getRollbackOnly
boolean getRollbackOnly() throws java.lang.IllegalStateException
Test if the transaction has been marked for rollback only. An enterprise bean instance can use this operation, for example, to test after an exception has been caught, whether it is fruitless to continue computation on behalf of the current transaction. Only enterprise beans with container-managed transactions are allowed to use this method.
Returns: True if the current transaction is marked for rollback, false otherwise. Throws: IllegalStateException — The Container throws the exception if the instance is not allowed to use this method (i.e. the instance is of a bean with bean-managed transactions).
getTimerService
TimerService getTimerService() throws java.lang.IllegalStateException
Throws: IllegalStateException — The Container throws the exception if the instance is not allowed to use this method (e.g. if the bean is a stateful session bean) Since: EJB 2.1
lookup
java.lang.Object lookup(java.lang.String name) throws java.lang.IllegalArgumentException
Lookup a resource within the java: namespace. Names referring to entries within the private component namespace can be passed as unqualified strings. In that case the lookup will be relative to «java:comp/env/» . For example, assuming an enterprise bean defines an ejb-local-ref with ejb-ref-name «ejb/BarRef» the following two calls to EJBContext.lookup are equivalent : ejbContext.lookup(«ejb/BarRef») ; ejbContext.lookup(«java:comp/env/ejb/BarRef») ;
Parameters: name — Name of the entry Throws: IllegalArgumentException — The Container throws the exception if the given name does not match an entry within the component’s environment. Since: EJB 3.0
getContextData
java.util.Map getContextData()
Returns the context data associated with this invocation or lifecycle callback. If there is no context data, an empty Map
Since: EJB 3.1
| ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2009-2011, Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to license terms.
Generated on 10-February-2011 12:41
java.lang.IllegalStateException: No EJB receiver available for handling (. )
Well, I tried to lookup an EJB in a standalone and it worked, only put my jndi.properties in the src and do the lookup and it works.
It seems that I can lookup an EJB, I have no error at the moment of the lookup, but, when I try to use some method of this same EJB, I’m getting this:
java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:ExampleEJBProject,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@57288854
I think the JNDI is right, because, when I try to put anything, even the lookup doesn’t work.
package org.ejb; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class EJBLocator < @SuppressWarnings("unchecked") public static T lookup(String jndi, Class clazz) throws NamingException < //Properties jndiProp = getProperties(); Properties jndiProp = getProperties2(); return (T) new InitialContext(jndiProp).lookup(jndi + "!" + clazz.getCanonicalName()); >private static Properties getProperties() < Properties jndiProp = new Properties(); jndiProp.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class .getName()); jndiProp.put(Context.PROVIDER_URL, "remote://192.168.1.101:4447"); jndiProp.put("jboss.naming.client.ejb.context", true); jndiProp.put( "jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); jndiProp.put("java.naming.security.principal", "root"); jndiProp.put("java.naming.security.credentials", "admin"); return jndiProp; >private static Properties getProperties2() < Properties jndiProp = new Properties(); jndiProp.put("endpoint.name", "client-endpoint"); jndiProp.put( "remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", false); jndiProp.put("remote.connections", "default"); jndiProp.put("remote.connection.default.host", "192.168.1.101"); jndiProp.put("remote.connection.default.port", "4447"); jndiProp.put( "remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", false); jndiProp.put("remote.connection.default.username", "root"); jndiProp.put("remote.connection.default.password", "admin"); return jndiProp; >>
And, my ManagedBean, the one that calls the EJBLocator.lookup()
package org.beans; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.context.FacesContext; import org.ejb.EJBLocator; import br.com.wehavescience.interfaces.CalculadoraRemote; @ManagedBean public class ClientBean < private CalculadoraRemote bean; public String calcular() < try < bean = EJBLocator.lookup("ejb:/ExampleEJBProject/CalculadoraBean", CalculadoraRemote.class); double result = bean.somar(2, 2); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(String.valueOf(result))); >catch (Exception ex) < ex.printStackTrace(); >return ""; > >
endpoint.name=client-endpoint remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=192.168.1.101 remote.connection.default.port = 4447 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false remote.connection.default.username=root remote.connection.default.password=admin
And, what I have changed in the standalone.xml
Anyone knows what is happening?
1. Re: java.lang.IllegalStateException: No EJB receiver available for handling (. )
I tried to search about this issue and people say that It is needed to put the jboss-ejb-client.properties in the classpath, but, I already did it, it seems that my jboss-ejb-client.properties has no use, because, if I remove or add it, nothing changes. When I coded the standalone and it worked, I just used the jndi.properties and new InitialContext().lookup(«ejb:/. «) and it worked, so, I tried it, but, I got this exception: 12:49:46,608 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) Caused by: java.lang.SecurityException: EJB client context selector may not be changed Even if I put the properties into the constructor parameter, like new InitialContext(props), I’m still getting this. I read about this exception too, and I found it:
EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration( ejbClientProperties); final ContextSelector ejbClientContextSelector = new ConfigBasedEJBClientContextSelector( ejbClientConfiguration); EJBClientContext.setSelector(ejbClientContextSelector);
2. Re: java.lang.IllegalStateException: No EJB receiver available for handling (. )
Are you trying to lookup a bean which is deployed on the same server as the client @ManagedBean? If yes, then you don’t need any of this. Just use the java:global, java:app or java:module JNDI names of the bean depending on the client. The JNDI names are displayed on the console when deploying them.
IllegalStateException
posted 20 years ago
I am using container managed transactions
A) in few methods i have transaction attribute as required
B) in few methods i have transaction attribute as supports
thus sometimes a method firing only select queris (methods in B) may be in transaction if called from A, or sometimes not in transaction if called directly
on getting any exception, i want to rollback transaction
using SessionContext.getUserTransaction() gives illegal state exception
sessionContext.setRollBackOnly() gives illegal state exception
the j2ee docs says that for container managed transcations THESE METHODS CANNOT BE CALLED
now, the question is how do i know in my ejb code whether current code is running under transactions or not !
Kalpesh Soni
[ July 28, 2007: Message edited by: Kalpesh Soni ]
Test 094, IBM WID 6.0 cert
SCJP 1.2
SCBCD 1.3 Beta
SCWCD 1.4 Beta
SCMAD Beta
SCDJWS Beta
KS
posted 20 years ago
First: where do you try to rollback the transaction, in the calling methods (TX_REQUIRED) or the failing query-methods (TX_SUPPORTS)?
In the ejb 2.1 pfd spec you can read:
17.3.4.2 javax.ejb.EJBContext.setRollbackOnly() method
An enterprise bean with container-managed transaction demarcation can use the setRollbackOnly() method of its EJBContext object to mark the transaction such that the transaction can never commit. Typically, an enterprise bean marks a transaction for rollback to protect data integrity before throwing an application exception, because application exceptions do not automatically cause the Containerc to rollback the transaction.