[jboss-user] [JBoss Seam] - Seam context problems in a web service

AnisBM do-not-reply at jboss.com
Fri Nov 23 05:46:31 EST 2007


Hi all,

I'm having problems with injection in web service. I think that it is due to context problem but I have no idea how to resolve it.

I'm using Seam 2.0.0.GA and JBoss 4.2.1.GA.

Here is my web service code :


  | @Stateless
  | @WebService(name = "Authentication")
  | @SOAPBinding(style = SOAPBinding.Style.RPC)
  | public class Authentication implements AuthenticationRemote {
  | 
  | 	@PersistenceContext
  | 	EntityManager em;
  | 	
  | 	@In(create=true)
  | 	UserHome userHome;
  | 	
  | 	@In(create=true)
  | 	EquipeHome equipeHome;
  | 	
  | 	@WebMethod
  | 	public void createUser(int equipeId, String loginName, String password,
  | 			String nom, String prenom, String email) {
  | 		User newUser = new User();
  | 		equipeHome.setEquipeEquipeId(equipeId);
  | 		newUser.setEquipe(equipeHome.find());
  | 		newUser.setLoginName(loginName);
  | 		newUser.setPassword(password);
  | 		newUser.setNom(nom);
  | 		newUser.setPrenom(prenom);
  | 		newUser.setEmail(email);
  | 		userHome.setInstance(newUser);
  | 		userHome.persist();	
  | 	}
  | 

The UserHome was made by SeamGen. Here is its code :


  | @Name("userHome")
  | public class UserHome extends EntityHome<User> {
  | 
  | 	@In(create = true)
  | 	EquipeHome equipeHome;
  | 
  | 	public void setUserUserId(Integer id) {
  | 		setId(id);
  | 	}
  | 
  | 	public Integer getUserUserId() {
  | 		return (Integer) getId();
  | 	}
  | 
  | 	@Override
  | 	protected User createInstance() {
  | 		User user = new User();
  | 		return user;
  | 	}
  | 
  | 	public void wire() {
  | 		Equipe equipe = equipeHome.getDefinedInstance();
  | 		if (equipe != null) {
  | 			getInstance().setEquipe(equipe);
  | 		}
  | 	}
  | 
  | 	public boolean isWired() {
  | 		if (getInstance().getEquipe() == null)
  | 			return false;
  | 		return true;
  | 	}
  | 
  | 	public User getDefinedInstance() {
  | 		return isIdDefined() ? getInstance() : null;
  | 	}
  | 
  | }
  | 

Here is the error message when I invoke my web service :


  | 11:40:05,655 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
  | javax.ejb.EJBException: java.lang.NullPointerException
  | 	at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
  | 	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
  | 	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
  | 	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:174)
  | 	at org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB3.invokeServiceEndpointInstance(ServiceEndpointInvokerEJB3.java:114)
  | 	at org.jboss.ws.core.server.AbstractServiceEndpointInvoker.invoke(AbstractServiceEndpointInvoker.java:207)
  | 	at org.jboss.ws.core.server.ServiceEndpoint.processRequest(ServiceEndpoint.java:212)
  | 	at org.jboss.ws.core.server.ServiceEndpointManager.processRequest(ServiceEndpointManager.java:448)
  | 	at org.jboss.ws.core.server.AbstractServiceEndpointServlet.doPost(AbstractServiceEndpointServlet.java:114)
  | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
  | 	at org.jboss.ws.core.server.AbstractServiceEndpointServlet.service(AbstractServiceEndpointServlet.java:75)
  | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
  | 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
  | 	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
  | 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  | 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
  | 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  | 	at java.lang.Thread.run(Thread.java:595)
  | Caused by: java.lang.NullPointerException
  | 	at authenticationGA.bean.session.Authentication.createUser(Authentication.java:52)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 	at java.lang.reflect.Method.invoke(Method.java:585)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
  | 	at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
  | 	at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
  | 	... 42 more
  | 

When I debugged it, I saw the error happened when I try to set the EquipeId of the equipeHome element.

So, I tried to adopt the way of the Seambay example but I still have an error message.

Here is the new code of the web service :


  | @Stateless
  | @WebService(name = "Authentication")
  | @SOAPBinding(style = SOAPBinding.Style.RPC)
  | public class Authentication implements AuthenticationRemote {
  | 
  | 	@PersistenceContext
  | 	EntityManager em;
  | 	
  | 	@WebMethod
  | 	public void createUser(int equipeId, String loginName, String password,
  | 			String nom, String prenom, String email) {
  | 		UserBean action = getUserBean();      
  | 	    action.createUser(equipeId, loginName, password, nom, prenom, email);	
  | 	}
  | 	
  | 	public UserBean getUserBean() {
  | 		return (UserBean) Component.getInstance(UserBean.class, true);
  | 	}
  | 
  | }
  | 

Here is the code of UserBean :


  | @Name("userBean")
  | public class UserBean implements Serializable {
  | 	
  | 	@In(create=true)
  | 	UserHome userHome;
  | 	
  | 	@In(create=true)
  | 	EquipeHome equipeHome;
  | 	
  | 	public void createUser(int equipeId, String loginName, String password,
  | 			String nom, String prenom, String email) {
  | 		User newUser = new User();
  | 		equipeHome.setEquipeEquipeId(equipeId);
  | 		newUser.setEquipe(equipeHome.find());
  | 		newUser.setLoginName(loginName);
  | 		newUser.setPassword(password);
  | 		newUser.setNom(nom);
  | 		newUser.setPrenom(prenom);
  | 		newUser.setEmail(email);
  | 		userHome.setInstance(newUser);
  | 		userHome.persist();
  | 	}
  | 
  | }
  | 

User is a simple entity bean.
Here is the error :


  | 11:08:19,957 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
  | javax.ejb.EJBException: java.lang.IllegalStateException: No application context active
  | 	at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
  | 	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
  | 	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
  | 	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:174)
  | 	at org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB3.invokeServiceEndpointInstance(ServiceEndpointInvokerEJB3.java:114)
  | 	at org.jboss.ws.core.server.AbstractServiceEndpointInvoker.invoke(AbstractServiceEndpointInvoker.java:207)
  | 	at org.jboss.ws.core.server.ServiceEndpoint.processRequest(ServiceEndpoint.java:212)
  | 	at org.jboss.ws.core.server.ServiceEndpointManager.processRequest(ServiceEndpointManager.java:448)
  | 	at org.jboss.ws.core.server.AbstractServiceEndpointServlet.doPost(AbstractServiceEndpointServlet.java:114)
  | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
  | 	at org.jboss.ws.core.server.AbstractServiceEndpointServlet.service(AbstractServiceEndpointServlet.java:75)
  | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
  | 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
  | 	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
  | 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  | 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
  | 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  | 	at java.lang.Thread.run(Thread.java:595)
  | Caused by: java.lang.IllegalStateException: No application context active
  | 	at org.jboss.seam.Component.forName(Component.java:1799)
  | 	at org.jboss.seam.Component.getInstance(Component.java:1849)
  | 	at org.jboss.seam.Component.getInstance(Component.java:1832)
  | 	at org.jboss.seam.Component.getInstance(Component.java:1811)
  | 	at authenticationGA.bean.session.Authentication.getUserBean(Authentication.java:79)
  | 	at authenticationGA.bean.session.Authentication.createUser(Authentication.java:45)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 	at java.lang.reflect.Method.invoke(Method.java:585)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
  | 	at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
  | 	at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
  | 	... 42 more
  | 


Thanks.

Best regards.
Anis

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4107289#4107289

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4107289



More information about the jboss-user mailing list