Hot questions for Using Enterprise JavaBeans in payara

Question:

I'm trying to deploy ear file, that contains ejb module in dependecies in Payara 5.184 and getting error:

11.02.2019 13:57:15.938 | [payara-executor-service-scheduled-task] | ERROR | Exception while deploying the app [my-ear-SNAPSHOT]
11.02.2019 13:57:15.945 | [payara-executor-service-scheduled-task] | ERROR | Exception during lifecycle processing
java.lang.IllegalArgumentException: Invalid ejb jar [lib/my-ejb.jar]: it contains zero ejb. 
Note: 
1. A valid ejb jar requires at least one session, entity (1.x/2.x style),
   or message-driven bean. 
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar. 
3. If the jar file contains valid EJBs which are annotated with EJB component
   level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton),
   please check server.log to see whether the annotations were processed properly.

With payara 4.1, this error does not occur. What should I do to fix the deployment error?

There is short version of my pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>my</groupId>
        <artifactId>my-ears</artifactId>
        <version>SNAPSHOT</version>
    </parent>
    <artifactId>my-ear</artifactId>
    <packaging>ear</packaging>
    <dependencies>
        <dependency>
            <groupId>my</groupId>
            <artifactId>my-ejb</artifactId>
            <version>${project.version}</version>
            <type>ejb</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <version>6</version>
                    <generateApplicationXml>true</generateApplicationXml>
                    <skinnyWars>true</skinnyWars>
                    <defaultJavaBundleDir>lib/</defaultJavaBundleDir>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <filtering>true</filtering>
                    <modules>
                        <ejbModule>
                            <groupId>my</groupId>
                            <artifactId>my-ejb</artifactId>
                            <bundleDir>/lib</bundleDir>
                        </ejbModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Answer:

The problem was in domain.xml. I just copy it from payara 4.1 config folder and it was the wrong decision. The correct approach is this: take the original file and consistently make changes to it. Unfortunately, there is one more problem with EJB, but all the errors described above are gone.

Question:

1.I try to read data from web-server, wich situated at some URL.

2.In our company I use e-Commerce API, wich works with the data from web-server.

3.To retrive the data at first I need to make pool of the data from web-server.

4.To make the pool of data I need to configure connection.

5.One part from step "I need to configure connection" is function getSession(), wich uses the Shiro api(org.apache.shiro.SecurityUtils) so wevery time when I try to make connection with web-server and use the data from the web-server i become an Exception "Exception in thread "main" org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration."

Befeore write this question I tried to look at logs and read abotut classes and problem, which descibe there.

This all runs on Windows 10, Java 8, Payara Server(Glassfish), with EJBAPI and some e-Commerce API.

Import that I use

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.InvalidSessionException;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

at

ContentConfiguration conf = new ContentConfiguration(
                getSessionId(), 
                Constant.ENTITYMODELL, 
                Constant.EMPTY, 
                context);
protected static Session getSession()
{
    Subject subject = SecurityUtils.getSubject();
    if(subject.isAuthenticated())
        return subject.getSession();
    else
        return null;
}

Error Message

Exception in thread "main" org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.
    at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
    at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)
    at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
    at de.kolb.demo.data.ServiceLocator.getSessionId(ServiceLocator.java:15)
    at de.kolb.demo.logic.CommonTest.getCommonData(CommonTest.java:32)
    at de.kolb.demo.presentation.ContentDirector.main(ContentDirector.java:34)

Answer:

I want to get answer which represent situation in my company, but a lot of principes, which i will to describe connect with common proplem in Shiro hub.

1.My problem connect with getSessionId() enter image description here

2.getSessionId() it's a function from company API. In this function i call org.apache.shiro.SecurityUtils.getSubject() enter link description here

  1. At this moment I thought about exception Message No SecurityManager accessible to the calling code.... Than I look at Shiro documentation here enter link description here. There i found, that every time when i use Aplication, which use authentication and autorisation i need to configure "SecurityManager" with "Realm" object.

    4.It is a small instruction and detailed instruction present at shiro site enter link description here