Call EJB@Liberty from junit?

What change should I do to make this ejb-call work ?
https://github.com/espre05/prem-ejb

– I have 2 junit for jboss ejb , works great!
– I have 2 junit for open ejb , works great!
– I have 1 junit for liberty ejb , Does not work!

Please let me know the code snippet change to call the ejb successfully.

Related:

java.lang.IllegalStateException: Required attribute is null,AtomicServiceReference[name=clientAuthenticationService,ctx=null,ref=null,svc=null]

Hi,

I write a client to connect remote EJB, and the client code like below.

public class RMITest
{
public class DSLoginConfiguration extends Configuration
{
public AppConfigurationEntry[] getAppConfigurationEntry(java.lang.String applicationName)
{
WSClientLoginModuleImpl loginModuleImpl = new WSClientLoginModuleImpl();
Hashtable h = new Hashtable();
h.put(
“delegate”, loginModuleImpl.getClass());
AppConfigurationEntry entry = new AppConfigurationEntry(
“com.ibm.ws.security.client.jaas.modules.WSLoginModuleProxy”,
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, h);
return new AppConfigurationEntry[] { entry };
}

public void refresh()
{
}
}

private String hostName;
private String password;
private String userName;
private InitialContext initialContext;

public RMITest(String hostName, String userName, String password)
{
this.hostName = hostName;
this.userName = userName;
this.password = password;
}

protected LoginContext createLoginContext(String userName, String password) throws Exception
{
Configuration config = new DSLoginConfiguration();
Configuration.setConfiguration(config);
LoginContext loginContext = new LoginContext(“ClientContainer”, new WSCallbackHandlerImpl(userName, “customRealm”,password));
return loginContext;
}

private void loginRMIproxy() throws Exception
{
LoginContext lc = createLoginContext(
userName, password);
lc.login();
Subject s = lc.getSubject();
System.out.println(“*****Subject*****” + s);
System.out.println(“*****Principals*****” + s.getPrincipals());
System.out.println(s.getPrincipals().size());
WSSubject.setRunAsSubject(s);
}

protected void runTest()
{
try
{
System.out.println(“************** Begin RMI Test **************”);
loginRMIproxy();
System.out.println(“************** End RMI Test **************”);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Then I write a main method to call runTest method, and the client code like below.

public class HelloWorldClient
{
public static void main(String[] args)
throws Exception
{
String hostName = “localhost”;
String userName = “quoc”;
String password = “April”;

RMITest rmiTest = new RMITest(hostName, userName, password);
rmiTest.runTest();
}
}

When I run HelloWorldClient, it throws following exception:

************** Begin RMI Test **************
javax.security.auth.login.LoginException: java.lang.IllegalStateException: Required attribute is null,AtomicServiceReference[name=clientAuthenticationService,ctx=null,ref=null,svc=null]
at com.ibm.wsspi.kernel.service.utils.AtomicServiceReference.getService(AtomicServiceReference.java:239)
at com.ibm.wsspi.kernel.service.utils.AtomicServiceReference.getServiceWithException(AtomicServiceReference.java:210)
at com.ibm.ws.security.client.internal.jaas.JAASClientService.getClientAuthenticationService(JAASClientService.java:372)
at com.ibm.ws.security.client.jaas.modules.WSClientLoginModuleImpl.login(WSClientLoginModuleImpl.java:110)
at com.ibm.ws.security.jaas.common.modules.WSLoginModuleProxy.login(WSLoginModuleProxy.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:788)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:196)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:698)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:696)
at java.security.AccessController.doPrivileged(AccessController.java:650)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:696)
at javax.security.auth.login.LoginContext.login(LoginContext.java:597)
at com.client.RMITest.loginRMIproxy(RMITest.java:78)
at com.client.RMITest.runTest(RMITest.java:91)
at com.client.HelloWorldClient.main(HelloWorldClient.java:19)

at javax.security.auth.login.LoginContext.invoke(LoginContext.java:890)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:196)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:698)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:696)
at java.security.AccessController.doPrivileged(AccessController.java:650)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:696)
at javax.security.auth.login.LoginContext.login(LoginContext.java:597)
at com.client.RMITest.loginRMIproxy(RMITest.java:78)
at com.client.RMITest.runTest(RMITest.java:91)
at com.client.HelloWorldClient.main(HelloWorldClient.java:19)

And my client uses bleow jars:
![alt text][1]

**I think some jars can not fit, but I can not find some information on info center. **

**Does anyone know how to fix this??**

**Thanks in advance.**

[1]: /answers/storage/temp/19306-jar.jpg

Related:

How to increase the transaction timeouts for WebSphere Portal ?

Typical exceptions:

– CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation of method …..
Exception data: com.ibm.websphere.csi.CSITransactionRolledbackException: Transaction rolled back; nested exception is:
javax.transaction.TransactionRolledbackException: Transaction is ended due to timeout

– javax.transaction.RollbackException: Transaction marked for rollback by external component. Possible timeout, increase transaction timeout value and try again.

Related:

Event ID 4193 — Transactions Processing

Event ID 4193 — Transactions Processing

Updated: February 22, 2008

Applies To: Windows Server 2008

The Microsoft Distributed Transaction Coordinator service (MSDTC) can coordinate transactions for a variety of protocols.

Event Details

Product: Windows Operating System
ID: 4193
Source: Microsoft-Windows-MSDTC
Version: 6.0
Symbolic Name: IDS_DTC_E_TMREENLISTMENTCOMPLETE_INDOUBT
Message: A resource manager performed recovery and called ReenlistmentComplete indicating that recovery was complete. However, there is at least one transaction that was enlisted with the resource manager whose state is still “In Doubt”%0

Resolve
Resolve the In Doubt transactions

The Microsoft Distributed Transaction Coordinator service (MSDTC) reported that the outcome for a transaction has a status of In Doubt. This means that there is no information available about the outcome of this transaction. This can happen if the connection between the MSDTC proxy and the transaction manager that is acting as the commit coordinator was lost. The transaction may have committed or not. MSDTC lost communication with that transaction manager after preparing, but before receiving, the information about the transaction’s outcome.

The transaction remains prepared and in doubt until communication is restored with the superior transaction manager. The system administrator can force the transaction to commit manually by using the Component Services administrative tool.

Ensure that all Resource Managers (RM) that enlist in MSDTC transactions are consistent. RMs operate with relational databases, Message Queuing, transactional files, and object-oriented databases. After you are sure that all RMs are consistent, commit the transaction manually.

To perform this procedure, you must have membership in Administrators, or you must have been delegated the appropriate authority.

To commit the transaction manually:

  1. Click Start, and then click Run.
  2. Type comexp.msc, and then click OK. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Continue.
  3. Click Component Services, click Computers, click My Computer, and then click Distributed Transaction Coordinator.
  4. Click Local DTC, and then click Transaction List.
  5. In the Transaction List, right-click the transaction with the status of In Doubt, point to Resolve, and then click Commit.

    When a transaction’s Commit outcome is forced (that is, when the transaction is committed manually), the transaction is designated as Forced Commit.

Verify

To perform this procedure, you must have membership in Administrators, or you must have been delegated the appropriate authority.

To verify that the Microsoft Distributed Transaction Coordinator service (MSDTC) is running properly:

  1. Click Start, and then click Command Prompt.
  2. At the command prompt, type sc query msdtc, and then press ENTER.
  3. The system responds with information about the service. Confirm that these two items appear: SERVICE_NAME: msdtc and STATE : 4 RUNNING.

Related Management Information

Transactions Processing

Application Server

Related:

EJB remote calls after 60 seconds lead to a rollbackOnly

I have an application which runs in an IBM WebSphere Application Server 8 and has an EJB 3.0 Stateless Bean. This bean calls a Service which consists of an EJB 2 Stateless Bean. The second bean is called in a for loop. This means is called at least 300 times. The process takes place in a transaction. The first bean is marked as such:

@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)

The second bean:

Stateless
Container

Sometimes the entire transaction takes more than 60 seconds. For this reason I set the transaction timeouts to 600 seconds:

totalTranLifetimeTimeout=”600″
LPSHeuristicCompletion=”ROLLBACK”
propogatedOrBMTTranLifetimeTimeout=”600″

But I still encounter a problem for which I didn’t find the cause and a solution. After 60 seconds from the first call the service (Method B) sets for the transaction the attribute rolebackonly on true. The methods runs till the end but there is nothing saved in the database because of this – everything is rolled back.

I could not find a solution to get more information about the component which sets it to true (the container or the database) and for which reason.

I hope I explained everything right and any idea or solution will be much appreciated.

Related: