[EJB 3.0] - Junit failed.
by samwan809
Hi,
I have the following problem when I tried to establish a JNDI connectoin from a remote machine to the EJB3 JBOSS server thought JNDI.
# ant test
Buildfile: build.xml
compile-test:
[javac] Compiling 4 source files
test:
[junit] Testsuite: Client
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit]
[junit] Null Test: Caused an ERROR
[junit] Client (wrong name: com/ip6networks/calling_card_registration/test/Client)
[junit] java.lang.NoClassDefFoundError: Client (wrong name: com/ip6networks/calling_card_registration/test/Client)
[junit] at java.lang.ClassLoader.defineClass1(Native Method)
[junit] at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
[junit] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:247)
[junit]
[junit]
[junit] Test Client FAILED
BUILD SUCCESSFUL
Total time: 4 seconds
Main program:
# cat Client.java
package com.ip6networks.calling_card_registration.test;
import com.ip6networks.calling_card_registration.test.Calculator;
import com.ip6networks.calling_card_registration.test.CalculatorRemote;
import com.ip6networks.calling_card_registration.test.ServiceLocator;
public class Client
{
public static void main(String[] args) throws Exception
{
Calculator calculator = getSession();
System.out.println("in Client class");
System.out.println("1 + 1 = " + calculator.add(1, 1));
System.out.println("1 - 1 = " + calculator.subtract(1, 1));
}
private static Calculator getSession() throws Exception {
Calculator mgr = null;
mgr = (Calculator) ServiceLocator.getInstance().getService("Calculator");
if (mgr == null) {
//throw new SystemErrorException("Unable to connect to service");
throw new Exception("Unable to connect to service");
} else {
return mgr;
}
}
}
It complained ServiceLocator..... cant be casted to Calculator.
Here is the ServiceLocator program:
# cat ServiceLocator.java
package com.ip6networks.calling_card_registration.test;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.*;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
public class ServiceLocator {
private Map<String, java.lang.Object> cache;
private static ServiceLocator ourInstance = new ServiceLocator();
private static final Log logger = LogFactory
.getLog(ServiceLocator.class);
public static ServiceLocator getInstance() {
return ourInstance;
}
private ServiceLocator() {
this.cache = Collections.synchronizedMap(
new HashMap<String, java.lang.Object>());
}
public java.lang.Object getService(String serviceName) {
String serviceHost = "192.168.1.242";
if (this.cache.containsKey(serviceName)) {
return this.cache.get(serviceName);
}
try {
java.lang.Object service = this.getContext(
serviceHost).lookup(
serviceName + "Bean/remote");
cache.put(serviceName, service);
return service;
} catch (Exception e) {
e.printStackTrace();
logger.error("Unable to bind to service "
+ serviceName + ". Hostname: " + serviceHost, e);
return null;
} catch (Throwable e) {
e.printStackTrace();
logger.error("Unable to bind to service "
+ serviceName + ". Hostname: " + serviceHost, e);
return null;
}
}
public java.lang.Object getService(String serviceName, String serviceHost) {
String key = serviceHost + "." + serviceName;
if (this.cache.containsKey(key)) {
return this.cache.get(key);
} else {
try {
java.lang.Object service = this.getContext(
serviceHost).lookup(
serviceName + "Bean/remote");
cache.put(key, service);
return service;
} catch (Exception e) {
logger.error("Unable to bind to service "
+ serviceName + ". Hostname: " + serviceHost);
return null;
}
}
}
private Context getContext(String serviceHost) throws javax.naming.NamingException
{
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, serviceHost + ":1099");
return new InitialContext(properties);
}
}
Thanks
Sam
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4243629#4243629
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4243629
17 years
[EJB 3.0] - Re: Calling stopDelivery causes a
by philipdodds
Its been a while :) but I finally got a little time to dig into this one a little more, in the end the bit that seems to bite me is the MessageInflowLocalProxy, when requesting the stopDelivery - messages are continuing to pass through the MDB. The flow of the requests to stop finally make it to the MessageInflowProxy which will request a release of the proxy - due to a small stack of debugging I was sure I had a transaction in flight and I get to the release method.
| protected void release(Object proxy) throws Throwable
| {
| // We are now released
| released.set(true);
|
| if (trace)
| log.trace("MessageEndpoint " + getProxyString(proxy) + " release " + Thread.currentThread());
|
| // Tidyup any outstanding delivery
| if (oldClassLoader != null)
| {
| try
| {
| finish("release", proxy, false);
| }
| catch (Throwable t)
| {
| log.warn("Error in release ", t);
| }
| }
| }
|
What I don't understand is that the oldClassLoader is null which means that the finish didn't get called - looking at that method that means that the finish doesn't get called and the transaction manager didn't get tidied up.
So I continued to dig around to see where the oldClassLoader gets set - it looks like it is done in the before and after, which would imply that the TransactionDemarcationStrategy in the JmsServerSession needs to be TraditionalXATransactionDemarcationStrategy (since that it checked for) in the onMessage. I appear to have an XATransactionDemarcationStrategy in place so before and after aren't called.
It looked like in the MessageInflowLocalProxy you look for the oldClassLoader in the delivery method too - if it is null you start a transaction.
| try
| {
| // Check for starting a transaction
| if (oldClassLoader == null)
| {
| boolean isTransacted = messageEndpointFactory.isDeliveryTransacted(methodInfo.getAdvisedMethod());
| startTransaction("delivery", proxy, container, method, args, isTransacted);
| }
| return container.localInvoke(methodInfo, args);
| }
|
when you try to release how do you perform the check to ensure that the transaction has completed (when the oldClassLoader is null)?
All this code is pretty new to me so excuse any things that I got patently wrong :) Any advice or help would be greatly appreciated.
Cheers
P
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4243625#4243625
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4243625
17 years
[JBoss Messaging] - Re:
by clebert.suconic@jboss.com
"timfox" wrote : "clebert.suconic(a)jboss.com" wrote : Take a look at jms-ds.xml
| |
| |
| | The JNDI is java:/XAConnectionFactory.
| |
| | (You need to use the local JNDI for that... just do new InitialContext(). As you may known java:/ means local VM).
| |
| |
| | you can just do:
| |
| |
| | InitialContext ctx = new IntialContext();
| | | ConnectionFactory cf = (ConnectionFactory)ctx.lookup("java:/XAConnectionFactory");
| | |
| |
| |
|
| That is NOT correct.
|
| If you lookup java:/XAConnectionFactory you will NOT be using JCA.
|
| There is a section on using JCA in the docs:
|
| http://labs.jboss.com/file-access/default/members/jbossmessaging/freezone...
|
|
Yes.. I remember that now...
What confused me was the JMSProviderLoader that still on the jms-ds.xml:
<connection-factories>
| <!--
| JMS Stuff
| -->
|
| <mbean code="org.jboss.jms.jndi.JMSProviderLoader" name="jboss.messaging:service=JMSProviderLoader,name=JMSProvider">
| <attribute name="ProviderName">DefaultJMSProvider</attribute>
| <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
| <attribute name="FactoryRef">java:/XAConnectionFactory</attribute>
| <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
| <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
| </mbean>
| <!--
| JMS XA Resource adapter, use this to get transacted JMS in beans
| -->
| <tx-connection-factory>
| <jndi-name>JmsXA</jndi-name>
| <xa-transaction/>
| <rar-name>jms-ra.rar</rar-name>
| <connection-definition>org.jboss.messaging.ra.JBMConnectionFactory</connection-definition>
| <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
| <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/DefaultJMSProvider</config-property>
| <max-pool-size>20</max-pool-size>
| <security-domain-and-application>JmsXARealm</security-domain-and-application>
| </tx-connection-factory>
| </connection-factories>
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4243617#4243617
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4243617
17 years
[JBoss Messaging] - Re: Messaging 1.4.0 SP3 with JBoss AS 4.2.3
by sahanal
facing exactly the same problem. we are using JBoss 4.2.3 GA with JBM 1.4. Do any one have solution for this?
Assuming this could be because of network issue, we changed the JBoss server bind address to loop back address, but still got the same error, showing,
2009-07-14 17:57:51,925 DEBUG [org.jboss.remoting.transport.socket.MicroSocketClientInvoker] SocketClientInvoker[25724e, bisocket://10.1.150.170:2050639998] disconnecting ...
2009-07-14 17:57:51,925 DEBUG [org.jboss.remoting.transport.socket.SocketWrapper] ClientSocketWrapper[Socket[addr=/127.0.0.1,port=4235,localport=56656].1440636] closing
2009-07-14 17:57:51,925 DEBUG [org.jboss.remoting.callback.ServerInvokerCallbackHandler] ServerInvokerCallbackHandler[ab474q-8irr1u-fx4e2z0n-1-fx4e2ze3-4+ab474q-8irr1u-fx4e2z0n-1-fx4e2zg9-9] shut down
Its quite urgent, can any one pls help?
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4243604#4243604
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4243604
17 years