[EJB 3.0] - newbie question: ejb3 tutorial examples
by Nikola Kolev
Nikola Kolev [http://community.jboss.org/people/ntk] created the discussion
"newbie question: ejb3 tutorial examples"
To view the discussion, visit: http://community.jboss.org/message/557408#557408
--------------------------------------------------------------
Hello community,
I'm new to JBoss and the javaEE environment, and after playing around with the tutorials I have come across a problem with the java naming service (simple problem probably but still one I have found hard to overcome)
What I did:
1. I took the "Stateless" tutorial source code and created a .jar from it (without the Client.java).
2. I deployed the new .jar in my JBoss AS distribution, which is the latest JBoss 5 release. Restarted JBoss.
3. I checked if it is deployed correctly on the JBoss admin console.
4. I modified the Client.java the following way ( the underlined code is what I added ).
package org.jboss.tutorial.stateless.client;
import java.util.Hashtable;
import org.jboss.tutorial.stateless.bean.Calculator;
import org.jboss.tutorial.stateless.bean.CalculatorRemote;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Client
{
public static void main(String[] args) throws Exception
{
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
InitialContext ctx = new InitialContext(properties);
Calculator calculator = (Calculator) ctx.lookup("CalculatorBean/remote");
System.out.println("1 + 1 = " + calculator.add(1, 1));
System.out.println("1 - 1 = " + calculator.subtract(1, 1));
}
}
.... and I received the following exception:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at org.jboss.tutorial.stateless.client.Client.main(Client.java:41)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 5 more
What am I doing wrong?
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/557408#557408]
Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 8 months
Re: [jboss-user] [Spring Integration] - got javax.naming.NameNotFoundException error about the jndi name configured in the jboss-spring.xml for BeanFactory
by Sara Hue
Sara Hue [http://community.jboss.org/people/sara0804] replied to the discussion
"got javax.naming.NameNotFoundException error about the jndi name configured in the jboss-spring.xml for BeanFactory"
To view the discussion, visit: http://community.jboss.org/message/557399#557399
--------------------------------------------------------------
Thank you Marius for the information and response.
What I did to deploy jboss snowdrop is I dropped the snowdrop-deployers-1.1.0.GA.jar, snowdrop-vfs-1.1.0.GA.jar, and snowdrop-weaving-1.1.0.GA.jar at jbossAs_home/server/default/lib. I use jdk1.6.
At \server\default\depooy\sportsclub.ear
+ lib
sportsclub-domain.jar
sportsclub-jpa-dao-1.0.jar
sportsclub-reservations-spring-1.0.jar
+ META-INF
application.xml
jboss-spring.xml
sportsclub-invoicing-ejb-1.0.jar
sportsclub-invoicing-webmvc.war
sportsclub-reservations-web-1.0.war
sportsclub-subscriptions-ejb-1.0.jar
sportsclub-subscriptions-web-1.0.war
start database
start JBossAS (no errors)
go to http://localhost:8080/sportsclub/invoicing http://localhost:8080/sportsclub/invoicing
enter anything in the search text box, the request failed.
The error log is below.
I cannot find "SpringDao" jndi name from jmx console.
I tried to move jboss-spring.xml to meta-info in sportsclub-invoicing-webmvc.war, I got same error.
Am I miss something else?
22:27:38,781 INFO [DispatcherServlet] FrameworkServlet 'spring-mvc-servlet': initialization completed in 1094 ms
22:27:48,953 ERROR [[spring-mvc-servlet]] Servlet.service() for servlet spring-mvc-servlet threw exception
javax.naming.NameNotFoundException: SpringDao not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.jboss.util.naming.Util.lookup(Util.java:222)
at org.jboss.util.naming.Util.lookup(Util.java:182)
at org.jboss.spring.support.SpringInjectionSupport.getObjectFromBeanFactory(SpringInjectionSupport.java:130)
at org.jboss.spring.support.SpringInjectionSupport.injectToField(SpringInjectionSupport.java:189)
at org.jboss.spring.support.SpringInjectionSupport.inject(SpringInjectionSupport.java:76)
at org.jboss.spring.callback.SpringLifecycleInterceptor.postConstruct(SpringLifecycleInterceptor.java:44)
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:597)
at org.jboss.ejb3.interceptors.aop.LifecycleCallbackInterceptorMethodInterceptor.invoke(LifecycleCallbackInterce
ptorMethodInterceptor.java:80)
at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:79)
at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_11773393.invoke(Inv
ocationContextInterceptor_z_setup_11773393.java)
at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:79)
at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
at org.jboss.aop.joinpoint.ConstructionInvocation.invokeNext(ConstructionInvocation.java:79)
at org.jboss.ejb3.EJBContainer.invokeCallback(EJBContainer.java:1119)
at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJBContainer.java:1133)
at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJBContainer.java:1144)
at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:93)
at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:56)
at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:51)
at org.jboss.ejb3.pool.ThreadlocalPool.create(ThreadlocalPool.java:53)
at org.jboss.ejb3.pool.ThreadlocalPool.get(ThreadlocalPool.java:93)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176)
at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHand
lerBase.java:207)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHand
lerBase.java:164)
at $Proxy335.findAccountsBySubscriberName(Unknown Source)
at org.jboss.snowdrop.samples.sportsclub.springmvc.AccountController.updateAccount(AccountController.java:59)
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:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker
.java:174)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationM
ethodHandlerAdapter.java:421)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerA
dapter.java:409)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.jav
a:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java
:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/557399#557399]
Start a new discussion in Spring Integration at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 8 months
Re: [jboss-user] [JBoss Microcontainer Development POJO Server] - Implementing a non-flat deployment for Weld Integration
by Flavia Rainone
Flavia Rainone [http://community.jboss.org/people/flavia.rainone%40jboss.com] replied to the discussion
"Implementing a non-flat deployment for Weld Integration"
To view the discussion, visit: http://community.jboss.org/message/557388#557388
--------------------------------------------------------------
With a temporary workaround to the beanManager issue (simply replaced "entry.getKey().getId().equals("flat"))" by "entry.getKey().getClass().getName().contains("org.jboss.weld.integration.")") I ran into an issue involving the service registry. I'm not sure if this is related to the beanManager issue or not, but the problem is that Weld complains if a new BDA created by Deployment.loadBDA method has a clean service registry:
DEPLOYMENTS IN ERROR:
Deployment "vfs:///home/fla/Development/projects/jbossas-trunk/testsuite/output/lib/weld-translator.ear_WeldBootstrapBean" is in error due to the following reason(s):
org.jboss.weld.exceptions.ForbiddenStateException: WELD-000117 Required service org.jboss.weld.injection.spi.EjbInjectionServices has not been specified, **ERROR**
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1370) [:2.2.0.Alpha6]
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1316) [:2.2.0.Alpha6]
So, I created a workaround to populate the loaded BDA service registry, just to see if the error would go away. DeploymentImpl initializes the loaded BDA service registry with a copy of the service registries of the BDAs contained in the DeploymentImpl (only services added during bootstrap).
This makes WeldNumberguessExampleUnitTestCase to pass, but WeldTranslatorExampleUnitTestCase still fails, stating that TranslatorControllerBean is ambigously defined:
DEPLOYMENTS IN ERROR:
Deployment "vfs:///home/fla/Development/projects/jbossas-trunkLATEST/testsuite/output/lib/weld-translator.ear_WeldBootstrapBean" is in error due to the
following reason(s): org.jboss.weld.exceptions.DeploymentException: WELD-001414 Bean name is ambiguous. Name translator resolves to beans
[org.jboss.weld.bean-BaseClassLoader@62b92dc2{vfs:///home/fla/Development/projects/jbossas-trunkLATEST/build/target/jboss-6.0.0-SNAPSHOT/server/all/deployers/resteasy.deployer}-SessionBean-TranslatorControllerBean, org.jboss.weld.bean-BaseClassLoader@7e7186b{vfs:///home/fla/Development/projects/jbossas-trunkLATEST/testsuite/output/lib/weld-translator.ear}-SessionBean-TranslatorControllerBean],
**ERROR**
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1370) [:2.2.0.Alpha6]
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1316) [:2.2.0.Alpha6]
at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:968) [:2.2.0.Alpha6]
at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkComplete(MainDeployerPlugin.java:82) [:6.0.0-SNAPSHOT]
at org.jboss.profileservice.dependency.ProfileControllerContext$DelegateDeployer.checkComplete(ProfileControllerContext.java:125) [:0.1.0.Alpha1]
at org.jboss.profileservice.plugins.deploy.actions.DeploymentStartAction.doPrepare(DeploymentStartAction.java:104) [:0.1.0.Alpha1]
at org.jboss.profileservice.management.actions.AbstractTwoPhaseModificationAction.prepare(AbstractTwoPhaseModificationAction.java:100) [:0.1.0.Alpha1]
at org.jboss.profileservice.management.ModificationSession.prepare(ModificationSession.java:87) [:0.1.0.Alpha1]
at org.jboss.profileservice.management.AbstractActionController.internalPerfom(AbstractActionController.java:234) [:0.1.0.Alpha1]
So, the problem is that Weld finds two EjbDescriptors of the same bean. One in the BDA that represents weld-translator.ear, included in the corresponding DeploymentImpl, and another one in the bda that has been loaded by the Deployment, representing resteasy.deployer.
If I still initialize the loaded BDA service registry with a copy of the other BDAs service registry, but this time adding a new, clean, JBossEJBServices to the loaded BDA serviceRegistry, and putting no EjbInjectionServices in it, I get a message complaining that the injection point has unsatisfied dependencies:
DEPLOYMENTS IN ERROR:
Deployment "vfs:///home/fla/Development/projects/jbossas-trunkLATEST/testsuite/output/lib/weld-translator.ear_WeldBootstrapBean" is in error due to the following reason(s): org.jboss.weld.exceptions.DeploymentException: WELD-001408 Injection point has unsatisfied dependencies. Injection point: field org.jboss.test.deployers.weld.translator.ejb.TranslatorControllerBean.translator; Qualifiers: [@javax.enterprise.inject.Default()], **ERROR**
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1370) [:2.2.0.Alpha6]
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1316) [:2.2.0.Alpha6]
If anybody wants to retrace my steps, there is a https://jira.jboss.org/browse/JBAS-8250 patch attached to Jira that can be applied to JBoss AS trunk. You can check loadBDA implementation http://anonsvn.jboss.org/repos/jbossas/trunk/weld-int/deployer/src/main/j... here.
So, what is expected from the ServiceRegistry of a newly created BDA? Should it be initialized with some services? Which ones?
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/557388#557388]
Start a new discussion in JBoss Microcontainer Development POJO Server at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 8 months
[Beginner's Corner] - JBOSS AS 6 M4 Issue: Can't connect remotely to HornetQ. Please help!!
by Ahmad Siddiqi
Ahmad Siddiqi [http://community.jboss.org/people/omarsiddiqi] created the discussion
"JBOSS AS 6 M4 Issue: Can't connect remotely to HornetQ. Please help!!"
To view the discussion, visit: http://community.jboss.org/message/557387#557387
--------------------------------------------------------------
I installed Jboss AS6 on my local machine and installed it as a windows service. The admin-console comes up fine and I can see everything setup correctly however I can't connect to the Queues via code from a remote computer although it works fine when i use localhost as my url. Following is the error that i'm getting
Error: javax.naming.CommunicationException: Could not obtain connection to any of these urls: 192.168.217.1:5445 and discovery failed with error: javax.naming.CommunicationException: Receive timed out Root exception is java.net.SocketTimeoutException: Receive timed outat org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1690)at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1761)at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:695)at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)at javax.naming.InitialContext.lookup(InitialContext.java:392)at HelloJms.runExample(HelloJms.java:51)at HelloJms.main(HelloJms.java:29) Caused by: java.net.SocketTimeoutException: Receive timed outat java.net.PlainDatagramSocketImpl.receive0(Native Method)at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:136)at java.net.DatagramSocket.receive(DatagramSocket.java:725)at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1659)
After reviewing various blogs I realized that AS6 sets everything up for you by itself. For example it sets up the NettyConnectors and NettyAcceptors by default and uses port 5445 as the default. Even though I attached the hornetq-configuration.xml with the post I want to show a partial view of the hornetq-configuration.xml I have for connectors and acceptors.
My client is extremely simple and all im doing in the client is loading my properties, specifying the url and port and trying to get a queue as follows.
Connection connection = null;
InitialContext initialContext = null;
TransportConfiguration config = new TransportConfiguration();
Properties props = new Properties();
// I've tried all sorts of urls here
props.put(Context.PROVIDER_URL, "jnp://192.168.217.1:1099");
props.put(Context.PROVIDER_URL, "jnp://192.168.217.1:5445");
props.put(Context.PROVIDER_URL, "jnp://192.168.217.1:5445");
props.put(Context.PROVIDER_URL, "jnp://ahmads-pc3:5445");
props.put(Context.PROVIDER_URL, "jnp://ahmads-pc3.saccap.int:1099"); // fullname.
props.put(Context.PROVIDER_URL, "jnp://ahmads-pc3.saccap.int:5445"); // fullname.
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES, "java.naming.factory.url.pkgs");
initialContext = new InitialContext(props);
ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/557387#557387]
Start a new discussion in Beginner's Corner at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 8 months